vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PointShell_Object_Data_LOD_Builder.h
Go to the documentation of this file.
1 #ifndef POINTSHELL_OBJECT_DATA_LOD_BUILDER_H
2 #define POINTSHELL_OBJECT_DATA_LOD_BUILDER_H
3 
4 #include <list>
5 #include <vector>
6 #include <queue>
7 #include <helpers/DynamicTree.h>
8 #include "String"
10 
11 namespace APSpacePartitioning {
12 
14 {
15 public:
17 
18  bool operator() (const std::pair<float,int>& first, const std::pair<float,int>& second) const{
19  if (first.first >= second.first){
20  return true;
21  } else {
22  return false;
23  }
24  }
25 };
26 
28 {
29 public:
31 
32  bool operator() (const std::pair<float,int>& first, const std::pair<float,int>& second) const{
33  if (first.first >= second.first){
34  return false;
35  } else {
36  return true;
37  }
38  }
39 };
40 
42  osg::Vec3f comPos; // position of a vertex used for coputation
43  osg::Vec3f comNorm; //normal used for computaions
44  int level; // level of vertice in a tree
45  int ancestor; // ancestor of a vertice in a tree
46  list<int> edges; // list of edges that has this vertex
47  list<int> childs; // list of childs in a tree
48  int id; // ID of this vertex // used only for outPut
49  float radius; // computation of bounding spheres
50  bool leaf; // points wheather this vertex is a leaf or not in a tree
51  float importance; // computed as an avarage deviation of angles of normals of polygons to normal of point.
52  bool visible; // false - the vertex has already been removed due to reduction
53  bool valid; // false means that the vertex may not be removed // special conditions
54 };
55 
57  float importance; // imporatnce of this edge
58  float dist; // length of a edge
59  float cost; // cost of a vertice
60  int id;
61  int p1,p2; // polygons adjacent to this edge
62  bool valid; // used to set edge as imporatnt or unable to remove. Edges with valid set to false will not be romoved or reduced.
63  bool visible; // used for checking if we are not lookng during a reduction to already reduced edges. Removed.
64  list<int> requiredDeletedEdges; // list of pairs of edges that al least one has to be removed from a queue before reduction of this is allowed
65  bool edgeCostRecompute; // TRUE declares that the edge may be recomputed.
66 };
67 
69  osg::Vec3f norm; // normal of this polygon
70  int e1,e2,e3; // edges of this polygon
71  bool visible; // used for checking wheather this polygon has already been removed or not.
72  int id;
73 };
74 
75 // just for internal use
76 struct int_3{
77  int i1;
78  int i2;
79  int i3;
80 };
81 
83 public:
86  void Clear();
87  // outbound communication
88  string getStatusResult(); // return in words the status after reduction.
89  int getZeroLevelSize(); // send a real zero level Size -- after computing it from percentage or by setting it.
90  int getPolygonsCount(){return iPolygonsCount;}; // returns polygons count
91 
92  // inbound communication
93  void setVerticesCount(int count); // sets the total count of a vertices in mesh
94  void setPolygonsCount(int count); // sets the total count of polygons in a mesh
95  void setEdgesCount(int count); // sets the total count of edges in a mesh
96  void setParameters(float lodEI, float lodEDI, float lodVI); // sets the imporatnce of 3 paramaters, lodEI - EdgeImporantce, lodEDI - EdgeDistance Imporatnce, lodVI - Vertex Imporatnce
97  void setMovableVertices(bool value); // sets wheater the new vertices should move or not after reduction
98  void setLevelZeroSize(int size,float percentage); // sets the size of a 0 level size.
99  void setFileName(string name); // sets the filename of a mesh which will be loaded.
100  void setMaxLevels(int levels); // sets maximal levels for a pointshell hierarchy
101  void setMaxChildrens(int maxChild); // sets maximum children per vertex
102  void setMinimumVertices(int minimum); //sets minimum of vertices that pointshell has to have
103 
104  // writing mesh into
105  void writeVertex(int seqnum,osg::Vec3f pos, osg::Vec3f norm); // writes a new vertex into a mesh
106  void writeVertex(int seqnum,osg::Vec3f pos); // writes a new vertex into a mesh
107  void writeEdge(int seqnum, int vertexPos1, int vertexPos2); // writes en edge into a mesh at selected position
108  void writeEdge(int seqnum, int vertexPos1, int vertexPos2, int polygon1, int polygon2); // writes en edge int oa mesh at selected position with additional parametres
109  void writePolygon(int seqnum, int v1, int v2, int v3); // writes a new polygon in a mesh
110 
111  // commands to print out statuses
112  void printOutQueue(); // prints out the whole queue at a actual state
113  void printOutStatus(); // prints out the status in a short version
114  void printOutVerbouseStatus(); // prints out the status in short version and all vertices,edges and polygons
115 
116  // commands for actions
117  void computeRadiusOfBoundingSpheres(); // computing distance for each verex to its child (!for all childs of childs ... )
118  void mergeLevels(); // merging levels in a tree
119  void finishStructureBuild(); // finish creation of a reduction structure. Prepares for building the ReductionLevelStructure
120  int subdivideMesh(); // subdivide mesh structure
121  int buildReductionLevelStructure(); // builds queue, reduce queue, sets level of vertices and sets leafes and childs. Returns specialCase
122 
123  // for actual build of a LOD Tree
124  int getMaxLvl(); //returns maximal Lvl found in a vertices
125  vector<VLOD> getLvlVertices(int lvl); // returns all vertices with rewuired level
126  vector<VLOD> getVertices(int seqNum); // returns all childs of a required vertice
127  vector<VLOD> getRoots(); // used for output. Returns all vertices with level 0
128 
129  //for actual output
130  vector<PointShell_Object_Data_Geometry::V> getVertices(); // returns all vertices of geometry
131  vector<PointShell_Object_Data_Geometry::E> getEdges(); // returns all edges of geometry
132  vector<PointShell_Object_Data_Geometry::P> getPolygons(); // returns all polygons of geometry
133 
134  PointShell_Object_Data_Geometry::V getVertex(int seqnum); // returns a vertex
135 
136 protected:
137  static const bool bDebug = false; // for debug only
138 
139  int specialCase; // spiecial case shows the error code of this class
140  bool moveVerticesPosition; // showing wheather calculate new position of vertex after reduction or use the one that has not been removed.
141  bool refillQueue; // used to find out wheather refill the queue or not
142  string filename; // File name of a reducted model // DEVEL not required for runtime version
143  int zeroLevelSize; // set the minimal amount of edges required on a 0 level of hierarchy
144  int maxLevels; //maximum depth of a tree
145  int maxChildrens; //maximum childrens per vertex
146  int minVertices; //minimum vertices that object has to have
147 
148  float maxDistance; // maximal distance from edges in model.
149  float lodEdgeImporatnce; // importance of an edge importnace in global cost of edge
150  float lodEdgeDistanceImporatnce; // importance of an edge length in global cost of edge
151  float lodVertexImporatnce; // imporatnce of an vertex inpormtance in global cost of edge
152 
153  // definition of a size of fields for edges, vertices and polygons.
154  // note that for size of vertex of X you need an size of polygons of 2X - 2 and for edges 3X-2 !
161 
162  // queue of edges waiting to be reduced and for subdivision.
163  priority_queue< pair<float,int>, vector<pair<float,int>>, mycomparisonMinMax > test_Queue;
164  priority_queue< pair<float,int>, vector<pair<float,int>>, mycomparisonMaxMin > test_Subdivision_Queue;
165 
166  // saving roots of a tree
167  vector<int> treeRoots;
168 
169  // creation of a geometry
170  void handleEdges(int polygon); // for a polygon the new edges are created or the polygons edges ID's are set
171  int_3 getEdges(int polygon); // returns edges of a polygon by checking edges whether they already exists // Chcecking is on basis of checking vertices
172 
173  //calulations and setting values on their basis
174  void calculateEdgesLength(); // calculates length of ALL edges
175  void calculateEdgeLength(int edge); // calculate length of required edge
176  void calculateEdgesImportance(); // calculate imporatnce of ALL edges
177  void calculateEdgeImportance(int seqnum); // calculate impratnce of required edges
178  void calculateEdgesCost(); // calculate cost of ALL edges
179  void calculateEdgeCost(int seqnum); // calculate cost of required edge
180  void calculateNormalOfPolygons(); // calcluates normals of ALL polygons
181  void calculateNormalOfPolygon(int seqnum); // calculate normal of required polygon
182  void calculateVerticesNormalAndImporatance(); // calculates normal and Imporatnce of ALL vertices
183  void calculateVertexNormalAndImportance(int seqnum); // calculate imporatance of required vertex
184  void calculateNewVertexPosition(int vertexToSet, int vt[3]); // calculates a new postition for vertexToSet from list of vertices
185 
186  // cleaning functions
187  void cleanVertexEdges(); // cleaning vertex edges from dualities and sorting it
188  inline void removeRequiredEdges(int edge); // removes list of required edges to remove first
189 
190  // setting a parameters for edges,vertices and polygons
191  inline void setVertexVisible(int vertex, bool visibility); // sets the visibility for the vertex
192  inline void setPolygonVisible(int polygon, bool visibility); // sets the visibility fot the polygon
193  inline void setEdgeVisible(int edge, bool visibility); // sets the visibility fot the edge
194  inline void addRequiredEdge(int edge, int reqEdge);
195  void setValidEdges();
196  inline void setValidEdge(int edge);
197  void setValidVertices();
198  inline void setValidVertex(int vertex, bool value);
199 
200  // math
201  inline float getAngle(osg::Vec3f vec1,osg::Vec3f vec2); // returns the angle of two normals/vectors
202  list<int> getSame(int* a, int* b); // returns pair that represents values that are in both fields
203  bool equalArrays(int a1[],int a2[],int size); // returs wheather the two arrays are same by content
204 
205  // deciding whather the edge may be reduces by looking at prerequisites
206  bool legalToRemoveEdge(int edge);
207 
208  //detection functions
209  inline bool polygonHaveVertex(int polygon, int vertex); // does the polygon has this vertex vertices?
210  inline bool polygonHaveVertices(int polygon, int v1 , int v2); // does the polygon has this vertex?
211  bool have2Polygons2OrMoreVetrticesSame(int p1,int p2); // does 2 polygons have 2 same vetices?
212  inline bool edgesEqualByVertices(int e1, int e2); // are the edges equal by vertices?
213  inline int getSameEdge(int p1,int p2); // returns the same edge of 2 poolygons
214  list<int> getSameEdges(int p1,int p2); // returns a pair of same 2 edges of both polygons
215  bool polygonsEqualsByVertices(int p1, int p2); // are the polygons equal by vertices?
216  inline int getThirdVertex(int polygon, int v1, int v2); //returns third vertex of polygon
217  inline pair<int,int> getOkAndChangeEdges(int polygon, int v1, int edge); // returns edge with v1 that is not edge as first and edge without v1 as second
218 
219  // output supporting functions
220  void computeVertexLevels(); // computes levels of vertices
221  void addVerticesLeafsAndChilds(); // prepares the vertice for output add leafs data and childs data!
222 
223  // computation of edge properities
224  inline float edgeCost(int edge);
225 
226  //returning inline functions
227  inline float edgeLength(int edge); // returns the lenght of edge
228  inline float edgeImportance(int edge); // returns the importance of edge
229  inline float vertexImportance(int vertex); // return the importance of vertex
230 
231  // printing functions
232  void printOutList(string log, list<int> edgesList); // prints out the given list
233  void printOutEdge(string log, int edge); // prints out the requested edge
234  void printOutVertex(string log, int vertex); // prints out the requested vertex
235  void printOutPolygon(string log, int polygon); // prints out the requested polygon
236 
237  //supporting output functions
238  string intToStr(int number); // int to String
239  string floatToTimeString(float time); // convert time in float (seconds) to String
240 
241  // Main Functions
242  void buildQueue(bool verbouse); // builds a queue from data found from edges,
243  int reduceFront(int); // reduce the queue. MAIN LOOP!
244 
245 };
246 
247 //end of namespace
248 }
249 
250 //end of definition POINTSHELL_OBJECT_DATA_LOD_BUILDER_H
251 #endif