MeshTex  3.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
MeshEntity.h
Go to the documentation of this file.
1 
7 /*
8  * Copyright 2012 Joel Baxter
9  *
10  * This file is part of MeshTex.
11  *
12  * MeshTex is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * MeshTex is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with MeshTex. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #if !defined(INCLUDED_MESHENTITY_H)
27 #define INCLUDED_MESHENTITY_H
28 
29 #include "AllocatedMatrix.h"
30 
31 #include "scenelib.h"
32 #include "ipatch.h"
33 #include "generic/callback.h"
34 
46 {
47 public: // public types
48 
53  {
57  };
58 
63  enum SliceType
64  {
68  };
69 
74  typedef Callback1<const char *, void> MessageCallback;
75 
80  typedef Callback2<float, float, void> TexInfoCallback;
81 
86  typedef struct {
87  float oldValue;
88  float rowDistance;
89  float colDistance;
90  float rowNumber;
91  float colNumber;
92  float constant;
94 
98  typedef struct {
99  bool maxSlice;
100  int index;
102 
108  typedef struct {
112 
121  template<typename ObjectClass, void (ObjectClass::*member)(float, float)>
123  public BindFirstOpaque2<Member2<ObjectClass, float, float, void, member> >
124  {
125  public:
131  TexInfoCallbackMethod(ObjectClass& object) :
132  BindFirstOpaque2<Member2<ObjectClass, float, float, void, member> >(object) {}
133  };
134 
135 public: // public methods
136 
138 
139  MeshEntity(scene::Node& mesh,
140  const MessageCallback& infoReportCallback,
141  const MessageCallback& warningReportCallback,
142  const MessageCallback& errorReportCallback);
143  ~MeshEntity();
145 
146 
147  bool IsValid() const;
148  void GetInfo(const int *refRow,
149  const int *refCol,
150  const TexInfoCallback *rowTexInfoCallback,
151  const TexInfoCallback *colTexInfoCallback);
153 
154 
155  void MinAlign(TextureAxisSelection axes);
156  void MaxAlign(TextureAxisSelection axes);
161 
162 
163  void SetScale(SliceType sliceType,
164  const SliceDesignation *alignSlice,
165  const RefSliceDescriptor *refSlice,
166  bool naturalScale,
167  float naturalScaleOrTiles);
168  void GeneralFunction(const GeneralFunctionFactors *sFactors,
169  const GeneralFunctionFactors *tFactors,
170  const SliceDesignation *alignRow,
171  const SliceDesignation *alignCol,
172  const RefSliceDescriptor *refRow,
173  const RefSliceDescriptor *refCol,
174  bool surfaceValues);
176 
177 private: // private methods
178 
180 
181  MeshEntity(const MeshEntity&);
182  const MeshEntity& operator=(const MeshEntity&);
184 
185 private: // private types
186 
191  {
195  };
196 
201  {
206  };
207 
212  {
215  };
216 
220  typedef struct {
222  float position;
223  int edgeSlice[NUM_SLICE_TYPES];
225 
230  typedef struct {
231  float scale;
232  float tiles;
233  float min;
234  float max;
235  } SliceTexInfo;
236 
244  typedef struct {
245  unsigned index;
248 
253  typedef bool(MeshEntity::*InternalImpl)(TextureAxis axis);
254 
255 private: // private template methods
256 
268  template<typename Element>
269  inline static Element& MatrixElement(Matrix<Element>& matrix,
270  SliceType sliceType,
271  int slice,
272  int index) {
273  return (sliceType == ROW_SLICE_TYPE ? matrix(slice, index) :
274  matrix(index, slice));
275  }
276 
277 private: // private methods
278 
280 
281  void UpdatePosMinMax(PositionAxis axis);
282  void UpdateTexMinMax(TextureAxis axis);
284 
285 
286  void CreateUndoPoint();
287  void CommitChanges();
289 
290 
291  int InternalSliceDesignation(const SliceDesignation *sliceDesignation,
292  SliceType sliceType);
293  RefSliceDescriptorInt *InternalRefSliceDescriptor(const RefSliceDescriptor *refSlice,
294  SliceType sliceType,
295  RefSliceDescriptorInt& refSliceInt);
297 
298 
299  float GetSliceTexScale(SliceType sliceType,
300  int slice,
301  TextureAxis axis,
302  float tiles);
303  bool GetSliceTexInfo(SliceType sliceType,
304  int slice,
305  TextureAxis axis,
306  SliceTexInfo& info);
307  void ReportSliceTexInfo(SliceType sliceType,
308  int slice,
309  TextureAxis axis,
310  char *messageBuffer,
311  unsigned messageBufferSize,
312  const TexInfoCallback *texInfoCallback);
314 
315 
316  void ProcessForAxes(InternalImpl internalImpl,
317  TextureAxisSelection axes);
318  void Shift(TextureAxis axis,
319  float shift);
320  void Scale(TextureAxis axis,
321  float scale);
322  bool MinAlignInt(TextureAxis axis);
323  bool MaxAlignInt(TextureAxis axis);
325  bool MinMaxAlignScale(TextureAxis axis,
326  ScaleOperation op);
330 
331 
333  float t,
334  const SlicePatchContext& context);
335  float SliceParametricSpeed(float t,
336  const SlicePatchContext& context);
337  float EstimateSegmentLength(float startPosition,
338  float endPosition,
339  const SlicePatchContext& context);
340  float RefineSegmentLength(float startPosition,
341  float endPosition,
342  const SlicePatchContext &context,
343  float segmentLengthEstimate,
344  float maxError);
346 
347 
349  const Matrix<float>& surfaceValues);
351  const Matrix<float>& values);
353  Matrix<float>& surfaceValues);
355  Matrix<float>& values);
356  void GenScaledDistanceValues(SliceType sliceType,
357  int alignSlice,
358  const RefSliceDescriptorInt *refSlice,
359  bool rawScale,
360  float rawScaleOrTiles,
361  Matrix<float>& values);
362  void GeneralFunctionInt(const GeneralFunctionFactors& factors,
363  TextureAxis axis,
364  int alignRow,
365  int alignCol,
366  bool surfaceValues,
367  const Matrix<float>& rowDistances,
368  const Matrix<float>& colDistances);
370 
371 private: // private static member vars
372 
382 
383 private: // private member vars
384 
388  scene::Node& _mesh;
389 
394  bool _valid;
395 
400  PatchControlMatrix _meshData;
401 
406 
411 
417 
424 
429 
435 
440 
445 
450 
455 
460 
465 };
466 
467 #endif // #if !defined(INCLUDED_MESHENTITY_H)