SphereMesh.cc

Go to the documentation of this file.
00001 #include <esg/mesh/SphereMesh.h>
00002 #include <assert.h>
00003 
00004 using namespace esg;
00005 
00006 /*
00007  * Topology of initial solid:
00008  */ 
00009 
00010 const Vector3 SphereMesh::INIT_VERTICES [6] = 
00011 {
00012     Vector3( 0,  1,  0),
00013     Vector3(-1,  0,  0),
00014     Vector3( 0,  0,  1),
00015     Vector3( 1,  0,  0),
00016     Vector3( 0,  0, -1),
00017     Vector3( 0, -1,  0)
00018 };
00019 
00020 const unsigned SphereMesh::FIRST_FACET_VERTICES   [3] = {0, 1, 2};
00021 const unsigned SphereMesh::SECOND_FACET_VERTICES  [3] = {0, 2, 3};
00022 const unsigned SphereMesh::THIRD_FACET_VERTICES   [3] = {0, 3, 4};
00023 const unsigned SphereMesh::FOURTH_FACET_VERTICES  [3] = {0, 4, 1};
00024 const unsigned SphereMesh::FIFTH_FACET_VERTICES   [3] = {5, 2, 1};
00025 const unsigned SphereMesh::SIXTH_FACET_VERTICES   [3] = {5, 3, 2};
00026 const unsigned SphereMesh::SEVENTH_FACET_VERTICES [3] = {5, 4, 3};
00027 const unsigned SphereMesh::EIGHTH_FACET_VERTICES  [3] = {5, 1, 4};
00028 
00029 const Vector3 SphereMesh::FIRST_FACET_NORMALS [3] =
00030 {
00031     INIT_VERTICES[FIRST_FACET_VERTICES[0]],
00032     INIT_VERTICES[FIRST_FACET_VERTICES[1]],
00033     INIT_VERTICES[FIRST_FACET_VERTICES[2]]
00034 };
00035 
00036 const Vector3 SphereMesh::SECOND_FACET_NORMALS [3] =
00037 {
00038     INIT_VERTICES[SECOND_FACET_VERTICES[0]],
00039     INIT_VERTICES[SECOND_FACET_VERTICES[1]],
00040     INIT_VERTICES[SECOND_FACET_VERTICES[2]]
00041 };
00042 
00043 const Vector3 SphereMesh::THIRD_FACET_NORMALS [3] =
00044 {
00045     INIT_VERTICES[THIRD_FACET_VERTICES[0]],
00046     INIT_VERTICES[THIRD_FACET_VERTICES[1]],
00047     INIT_VERTICES[THIRD_FACET_VERTICES[2]]
00048 };
00049 
00050 const Vector3 SphereMesh::FOURTH_FACET_NORMALS [3] =
00051 {
00052     INIT_VERTICES[FOURTH_FACET_VERTICES[0]],
00053     INIT_VERTICES[FOURTH_FACET_VERTICES[1]],
00054     INIT_VERTICES[FOURTH_FACET_VERTICES[2]]
00055 };
00056 
00057 const Vector3 SphereMesh::FIFTH_FACET_NORMALS [3] =
00058 {
00059     INIT_VERTICES[FIFTH_FACET_VERTICES[0]],
00060     INIT_VERTICES[FIFTH_FACET_VERTICES[1]],
00061     INIT_VERTICES[FIFTH_FACET_VERTICES[2]]
00062 };
00063 
00064 const Vector3 SphereMesh::SIXTH_FACET_NORMALS [3] =
00065 {
00066     INIT_VERTICES[SIXTH_FACET_VERTICES[0]],
00067     INIT_VERTICES[SIXTH_FACET_VERTICES[1]],
00068     INIT_VERTICES[SIXTH_FACET_VERTICES[2]]
00069 };
00070 
00071 const Vector3 SphereMesh::SEVENTH_FACET_NORMALS [3] =
00072 {
00073     INIT_VERTICES[SEVENTH_FACET_VERTICES[0]],
00074     INIT_VERTICES[SEVENTH_FACET_VERTICES[1]],
00075     INIT_VERTICES[SEVENTH_FACET_VERTICES[2]]
00076 };
00077 
00078 const Vector3 SphereMesh::EIGHTH_FACET_NORMALS [3] =
00079 {
00080     INIT_VERTICES[EIGHTH_FACET_VERTICES[0]],
00081     INIT_VERTICES[EIGHTH_FACET_VERTICES[1]],
00082     INIT_VERTICES[EIGHTH_FACET_VERTICES[2]]
00083 };
00084 
00085 
00086 
00087 
00088 /*
00089  * Methods definition:
00090  */
00091 
00092 
00093 void SphereMesh::_mesh(unsigned actDepth, unsigned maxDepth)
00094 {
00095   if (actDepth == maxDepth) return;
00096 
00097   /*
00098    * firstly split all edges:
00099    */
00100   int         newVert = -1;
00101   Vector3     v;
00102   Mesh::Vert* pVert;
00103   Mesh::Edge* pE = pSolid->first_edge;
00104   Mesh::Edge* pLastEdge = pSolid->first_edge->previous_edge;
00105   assert(pE);
00106 
00107   do {
00108       v.set(pE->V1->x, pE->V1->y, pE->V1->z);
00109       v.add(Vector3(pE->V2->x, pE->V2->y, pE->V2->z));
00110       v.scale(.5);
00111       v.normalize();
00112       pVert = NewVertex(pSolid, v.x, v.y, v.z);
00113       _store_vertex(pVert);
00114       if (newVert == -1) newVert = pVert->jmeno_vrcholu;
00115       pVert->normal.set(v);
00116       pVert->normal.set(v);
00117       (void) _split_edge(pE, pVert);
00118       pE = pE->next_edge;
00119   } while (pE->previous_edge != pLastEdge);
00120 
00121 
00122   /*
00123    * then split facets:
00124    */
00125   unsigned     vindex[3];
00126   Vector3      fnormal;
00127   Vector3      auxv;
00128   Mesh::Vert*  vin;
00129   Mesh::Vert*  vout;
00130   Mesh::Vert*  pV1;
00131   Mesh::Vert*  pV2;
00132   Mesh::Plane* pP         = pSolid->first_plane;
00133   Mesh::Plane* pLastPlane = pP->previous_plane;
00134   Mesh::Plane* pAuxP;
00135   do {
00136       for (int i = 0; i < 3; i++) {
00137           pE = pP->any_edge;
00138           Orient_Edge(pE, pP, &vin, &vout);
00139           while (vout->jmeno_vrcholu < newVert)
00140               pE = Next_Edge_in_loop(pE,&vin,&vout);
00141           pV1 = vout;
00142           vindex[0] = vout->jmeno_vrcholu;
00143           pE = Next_Edge_in_loop(pE,&vin,&vout);
00144           vindex[1] = vout->jmeno_vrcholu;
00145           pE = Next_Edge_in_loop(pE,&vin,&vout);
00146           vindex[2] = vout->jmeno_vrcholu;
00147           pV2 = vout;
00148           pAuxP = _split_plane(pP, pV1, pV2);
00149           assert(pAuxP);
00150           fnormal.set(_plane_normal(vindex,0,1,2));
00151           auxv.set(vout->x, vout->y, vout->z);
00152           pAuxP->a = fnormal.x;
00153           pAuxP->b = fnormal.y;
00154           pAuxP->c = fnormal.z;
00155           pAuxP->d = -fnormal.dot(auxv);
00156       }
00157       pP = pP->next_plane;
00158   } while (pP->previous_plane != pLastPlane);
00159   
00160   _mesh(actDepth+1, maxDepth);
00161 }
00162 
00163 
00164 
00165 //----------------------- public -----------------------------------
00166 
00167 SphereMesh::SphereMesh(unsigned recursion)
00168     : PolygonalMesh(INIT_VERTICES, 6)
00169 {
00170     bool ok = true;
00171 
00172     if (ok) ok = addFacet(FIRST_FACET_VERTICES,
00173                           FIRST_FACET_NORMALS,
00174                           3);
00175 
00176     if (ok) ok = addFacet(SECOND_FACET_VERTICES,
00177                           SECOND_FACET_NORMALS,
00178                           3);
00179 
00180     if (ok) ok = addFacet(THIRD_FACET_VERTICES,
00181                           THIRD_FACET_NORMALS,
00182                           3);
00183 
00184     if (ok) ok = addFacet(FOURTH_FACET_VERTICES,
00185                           FOURTH_FACET_NORMALS,
00186                           3);
00187 
00188     if (ok) ok = addFacet(FIFTH_FACET_VERTICES,
00189                           FIFTH_FACET_NORMALS,
00190                           3);
00191 
00192     if (ok) ok = addFacet(SIXTH_FACET_VERTICES,
00193                           SIXTH_FACET_NORMALS,
00194                           3);
00195 
00196     if (ok) ok = addFacet(SEVENTH_FACET_VERTICES,
00197                           SEVENTH_FACET_NORMALS,
00198                           3);
00199 
00200     if (ok) ok = addFacet(EIGHTH_FACET_VERTICES,
00201                           EIGHTH_FACET_NORMALS,
00202                           3);
00203 
00204     if (ok && pSolid) _mesh(0, recursion);
00205 }
00206 

Generated on Wed Jun 28 12:24:32 2006 for esg by  doxygen 1.4.6