libmove3d
3.13.0
|
00001 /* 00002 * Copyright (c) 2007 Florent Lamiraux 00003 * 00004 * Permission to use, copy, modify, and distribute this software for any 00005 * purpose with or without fee is hereby granted, provided that the above 00006 * copyright notice and this permission notice appear in all copies. 00007 * 00008 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 00009 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 00010 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 00011 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 00012 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 00013 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 00014 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00015 * 00016 */ 00017 00018 #ifndef GROUND_HEIGHT_H 00019 #define GROUND_HEIGHT_H 00020 #ifdef __cplusplus 00021 00022 #include <stddef.h> 00023 #include <vector> 00024 00036 class CgroundHeight 00037 { 00038 public: 00049 CgroundHeight(unsigned int inNbTrianglesPerSquare): 00050 attInitialized(false), attFiltering(true), attGroundXMin(1e30), attGroundYMin(1e30), attGroundXMax(-1e30), 00051 attGroundYMax(-1e30), attNbSquaresAlongX(0), attNbSquaresAlongY(0), attSquareSize(0), 00052 attTriangleIndexVectorArray(NULL), attAverageNbTrianglesPerSquare(inNbTrianglesPerSquare) {} 00056 CgroundHeight(): 00057 attInitialized(false), attFiltering(false), attGroundXMin(1e30), attGroundYMin(1e30), attGroundXMax(-1e30), 00058 attGroundYMax(-1e30), attNbSquaresAlongX(0), attNbSquaresAlongY(0), attSquareSize(0), 00059 attTriangleIndexVectorArray(NULL), attAverageNbTrianglesPerSquare(0) {} 00064 ~CgroundHeight(); 00065 00069 unsigned int averageNbTrianglesPerSquare() { 00070 return attAverageNbTrianglesPerSquare; 00071 } 00072 00076 void initializeGrid(); 00077 00096 unsigned int addVertex(const double & inX = 0., const double & inY = 0., const double & inZ = 0.); 00097 00104 bool addTriangle(unsigned int inPt1, unsigned int inPt2, unsigned int inPt3); 00105 00122 bool intersectionVerticalLineWithGround(double inX, double inY, double& groundHeight); 00123 00137 unsigned int countTriangles() { return attTriangleVector.size();}; 00138 00142 bool triangleAtRank(unsigned int inRank, double& outX1, double& outY1, double& outZ1, 00143 double& outX2, double& outY2, double& outZ2, 00144 double& outX3, double& outY3, double& outZ3); 00145 00149 private: 00150 00151 /* 00152 00153 P R I V A T E T Y P E S 00154 00155 */ 00159 typedef struct Ttriangle { 00160 unsigned int pt1; 00161 unsigned int pt2; 00162 unsigned int pt3; 00163 } Ttriangle; 00164 00168 typedef struct T3dPoint { 00169 double x; 00170 double y; 00171 double z; 00172 } T3dPoint; 00173 00174 /* 00175 00176 P R I V A T E M E T H O D S 00177 00178 */ 00179 00183 void boundingRectangleOfTriangle(const Ttriangle& triangle, 00184 double& xminTriangle, 00185 double &yminTriangle, 00186 double& xmaxTriangle, 00187 double& ymaxTriangle); 00188 00194 bool computeGroundBoundingRectangle(); 00195 00196 /* 00197 \brief Test whether one of the vertices of a triangle is inside a square. 00198 00199 Square edges are aligned with coordinate axis. 00200 00201 \param x1,y1 coordinates of first vectex of the triangle. 00202 \param x2,y2 coordinates of second vectex of the triangle. 00203 \param x3,y3 coordinates of third vectex of the triangle. 00204 00205 \param xMinSquare, yMinSquare, xMaxSquare, yMaxSquare two opposite vertices of the square. 00206 */ 00207 00208 bool isTriangleInsideSquare(double x1, double y1, 00209 double x2, double y2, 00210 double x3, double y3, 00211 double xMinSquare, double yMinSquare, 00212 double xMaxSquare, double yMaxSquare); 00213 00214 /* 00215 \brief Test whether a point lies inside a triangle. 00216 00217 \param x,y Coordinates of the point. 00218 \param x1,y1,x2,y2,x3,y3 Vectices of the triangle. 00219 00220 */ 00221 00222 bool isPointInsideTriangle(double x, double y, 00223 double x1, double y1, 00224 double x2, double y2, 00225 double x3, double y3); 00226 00227 00228 /* 00229 \brief Test whether one of the vertices of a square is inside a triangle 00230 00231 Square edges are aligned with coordinate axis. 00232 00233 \param x1,y1,x2,y2,x3,y3 Vertices of the triangle. 00234 \param xMinSquare, yMinSquare,xMaxSquare,yMaxSquare Two opposite vertices of the square. 00235 */ 00236 00237 bool isSquareInsideTriangle(double x1, double y1, 00238 double x2, double y2, 00239 double x3, double y3, 00240 double xMinSquare, double yMinSquare, 00241 double xMaxSquare, double yMaxSquare); 00242 00243 00244 /* 00245 \brief Test whether two segments intersect. 00246 00247 \param x1,y1,x2,y2 Extremities of first line-segment. 00248 \param x3,y3,x4,y4 Extremities of second line-segment. 00249 00250 */ 00251 00252 bool doSegmentsIntersect(double x1, double y1, 00253 double x2, double y2, 00254 double x3, double y3, 00255 double x4, double y4); 00256 00257 00258 /* 00259 \brief Test whether the edges of a triangle and of a square intersect. 00260 00261 Square edges are aligned with coordinate axis. 00262 00263 \param x1,y1,x2,y2,x3,y3 Vertices of the triangle. 00264 \param xMinSquare, yMinSquare,xMaxSquare,yMaxSquare Two opposite vertices of the square. 00265 00266 */ 00267 bool doEdgesIntersect(double x1, double y1, 00268 double x2, double y2, 00269 double x3, double y3, 00270 double xMinSquare, double yMinSquare, 00271 double xMaxSquare, double yMaxSquare); 00278 bool doesTriangleIntersectSquare(const Ttriangle& triangle, 00279 unsigned int i, unsigned int j); 00280 00281 00282 00286 void computeSizeAndNumberOfSquares(); 00287 00297 bool intersectionVerticalLineWithTriangle(const Ttriangle& triangle, double inX, 00298 double inY, double& groundHeight); 00299 00300 /* 00301 00302 P R I V A T E A T T R I B U T E S 00303 00304 */ 00305 00309 bool attInitialized; 00313 bool attFiltering; 00317 std::vector<T3dPoint> attVertexVector; 00318 00322 std::vector<Ttriangle> attTriangleVector; 00323 00327 double attGroundXMin; 00331 double attGroundYMin; 00335 double attGroundXMax; 00339 double attGroundYMax; 00343 unsigned int attNbSquaresAlongX; 00347 unsigned int attNbSquaresAlongY; 00348 /* 00349 \brief Size of squares 00350 */ 00351 double attSquareSize; 00352 /* 00353 Number of polyhedra for this floor 00354 int nb_polyhedron; 00355 */ 00356 /* array of polyhedra for this floor 00357 poly_polyhedre** polyhedron_array; */ 00358 00359 /* 00360 \brief Vector of facet indices for each square 00361 00362 Index correspond to vector attTriangleVector. 00363 */ 00364 std::vector<unsigned int>** attTriangleIndexVectorArray; 00365 00369 unsigned int attAverageNbTrianglesPerSquare; 00370 }; 00371 00372 #endif /* __cplusplus */ 00373 00374 #endif