MeshKit  1.0
ProjectShell.hpp
Go to the documentation of this file.
00001 //-----------------------------------C++-------------------------------------//
00002 // File: src/algs/ProjectShell.hpp
00003 // Wednesday February 11 10:50 2011
00004 // Brief: ProjectShell class definition: one scheme is provided to project a 2D
00005 //        surface, the shell, bounding a convex 3D region onto a plane.
00006 //---------------------------------------------------------------------------//
00007 
00008 #ifndef MESHKIT_PROJECTSHELL_HPP
00009 #define MESHKIT_PROJECTSHELL_HPP
00010 
00011 #include "meshkit/MeshScheme.hpp"
00012 #include "meshkit/iGeom.hpp"
00013 #include "meshkit/Matrix.hpp"
00014 #include "iMesh.h"
00015 
00016 #include <vector>
00017 #include <map>
00018 #include <list>
00019 #include <sys/resource.h>
00020 #include <fstream>
00021 
00022 
00023   //===========================================================================//
00033   //===========================================================================//
00034 namespace MeshKit {
00035 class ProjectShell : public MeshScheme {
00036 public:
00037   // Constructor
00038   ProjectShell(MKCore *mk_core, const MEntVector &me_vec = MEntVector());
00039   
00040   //return the type of entities in the created mesh
00041   void mesh_types(std::vector<moab::EntityType> &tps);
00042   
00043   //set up the projection parameters: the direction of projection
00044   virtual void setup_this();
00045   
00046   // Generate the projected mesh
00047   virtual void execute_this();
00048   
00049   // Destructor
00050   virtual ~ProjectShell();
00051   
00052 
00053   // Parameters controlling the behavior of ProjectShell
00054   Vector<3>& direction() {return m_direction;};
00055   bool&      dbg()       {return m_dbg;};
00056 
00057 private:
00058   // These are auxiliary constructs used to check the mesh in 3D
00059   struct Node {
00060     int id; // from 0, into vert_adj array
00061     Vector<3> xyz;
00062     std::list<int> edges;
00063   };
00064   
00065   struct Edge {
00066     int id; // from 0, into new created ps_edges array
00067     int v[2]; // index in adj_vert_coord array // used for construction of the edge array
00068     // always v[0] < v[1];
00069     int used;// count how many times is used in the mesh; more than 2 times is troublesome
00070     int t[2]; // triangle indices ; init with 0
00071     std::list<int> extraNodes; // they will be intersection nodes, different from original projection nodes
00072   };
00073   
00074   struct Triangle3D
00075   {
00076     int v[3];
00077     int e[3]; // edge indices: can be negative, but not 0 (orientation is important)
00078     int t[3]; // adjacent triangles
00079   };
00080   
00081   struct Triangle2D 
00082   {
00083     int v[3]; // vertices: indices in the m_xy array; start from 0
00084     int e[3]; // edges that are indices in original ps_edge array; these are used only for blue triangles (or red?)
00085     // the new extra intersection points will belong to edges of the blue triangles
00086     // or the alternate is to create points every time, and merge at the end the nodes?
00087     int t[3]; // neighbors: boundary or other of same color // triangles start from 0 too
00088     // boundary is flagged with _numPos (neg) + 1;
00089     // the indices are in this array (from 0 to  
00090     int oldId; // the index in the ps_triangle array; some triangles are eliminated because they project to 0 area
00091     double area; // will keep an area of the triangle;
00092     // it would be used mostly for debugging purposes
00093   };
00094   
00095   struct FinalTriangle
00096   {
00097     int v[3];  // these are new vertices that may be formed by intersections
00098     // they will be indices in the new array of vertices
00099     // 
00100     int redTriangle, blueTriangle;// intersection between 2 triangles is a convex polygon with at most 6 edges
00101     // it can be decomposed in at most 4 triangles; we do not care about quality
00102   };
00103   
00104   int getMesh(){};
00105   int getShellMesh();
00106   int checkMeshValidity();
00107   int projectIn2D();
00108   int commitMesh(){};
00109   int commitProjectedMesh();
00110   int computeIntersections();
00111   
00112   int getEdge(Node & v1, Node & v2, int & edgeId, Edge * edgesArr, int sizeArr);
00113   
00114   // this method computed intersection between 2 triangles: will output n points, area, affected sides
00115   int computeIntersectionBetweenRedAndBlue(int red, int blue, double * opPoints, int & oNPoints, double & area,
00116                                            int * opSides); 
00117   // this method will add extra points (P) for intersection points
00118   // they will stay on the red edgesi; will create the final triangles (in 2D) and
00119   //  extra nodes (if needed)
00120   //
00121   int findNodes(int red, int blue, double * iP, int nP);
00122 
00123   int edgeIntersections(double * red, double * blue, int mark[3], double * points, int & nPoints);
00124 
00125   double area2D(Vector<2> a, Vector<2> b, Vector<2> c) {
00126     Matrix<2,2> M;
00127     M.set_column(1,b-a);
00128     M.set_column(2,c-a);
00129     return det(M);
00130   }
00131 
00132 private:
00133   Vector<3> m_direction;
00134   Vector<3> m_dirX;
00135   Vector<3> m_dirY;
00136   
00137   int m_numNodes;
00138   int m_numTriangles;
00139   double * m_xyz ; // original coordinates
00140   int * m_triangles; // original triangles
00141   
00142   Edge  * ps_edges ;
00143   int m_numEdges;
00144   Node * ps_nodes ;
00145   Triangle3D * ps_triangles;
00146   
00147   double * m_xy; // 2d coordinates
00148   Triangle2D * m_redMesh;
00149   Triangle2D * m_blueMesh;
00150   std::vector <FinalTriangle> m_finalMesh;
00151   int m_numCurrentNodes;
00152   int m_numFinalTriangles;
00153   int m_numPos, m_numNeg;  
00154   int m_num2dPoints;
00155   int m_2dcapacity;
00156 
00157   bool m_dbg;
00158   std::ofstream m_dbg_out;
00159 };// class ProjectShell
00160 }// namespace MeshKit
00161 
00162 #endif  //  MESHKIT_PROJECTSHELL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines