Commit 627a0a0d authored by Pierre Kraemer's avatar Pierre Kraemer

correction intersection.hpp

parent 80f7c7ec
...@@ -38,15 +38,14 @@ namespace Geometry ...@@ -38,15 +38,14 @@ namespace Geometry
{ {
template <typename PFP> template <typename PFP>
bool intersectionLineConvexFace(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& positions, const typename PFP::VEC3& P, const typename PFP::VEC3& Dir, typename PFP::VEC3& Inter) bool intersectionLineConvexFace(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, const typename PFP::VEC3& P, const typename PFP::VEC3& Dir, typename PFP::VEC3& Inter)
{ {
typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::VEC3 VEC3 ;
const float SMALL_NUM = std::numeric_limits<typename PFP::REAL>::min() * 5.0f; const float SMALL_NUM = std::numeric_limits<typename PFP::REAL>::min() * 5.0f;
VEC3 p1 = positions[d]; VEC3 p1 = position[d];
VEC3 n = faceNormal<PFP>(map,d,positions); VEC3 n = faceNormal<PFP>(map,d,position);
VEC3 w0 = P - p1; VEC3 w0 = P - p1;
float a = -(n*w0); float a = -(n*w0);
float b = n*Dir; float b = n*Dir;
...@@ -58,7 +57,7 @@ bool intersectionLineConvexFace(typename PFP::MAP& map, Dart d, const typename P ...@@ -58,7 +57,7 @@ bool intersectionLineConvexFace(typename PFP::MAP& map, Dart d, const typename P
Inter = P + r * Dir; // intersect point of ray and plane Inter = P + r * Dir; // intersect point of ray and plane
// is I inside the face? // is I inside the face?
VEC3 p2 = positions[map.phi1(d)]; VEC3 p2 = position[map.phi1(d)];
VEC3 v = p2 - p1 ; VEC3 v = p2 - p1 ;
VEC3 vInter = Inter - p1; VEC3 vInter = Inter - p1;
float dirV = v * vInter; float dirV = v * vInter;
...@@ -69,7 +68,7 @@ bool intersectionLineConvexFace(typename PFP::MAP& map, Dart d, const typename P ...@@ -69,7 +68,7 @@ bool intersectionLineConvexFace(typename PFP::MAP& map, Dart d, const typename P
while(it != d) while(it != d)
{ {
p1 = p2; p1 = p2;
p2 = positions[map.phi1(it)]; p2 = position[map.phi1(it)];
v = p2 - p1; v = p2 - p1;
vInter = Inter - p1; vInter = Inter - p1;
float dirD = v * vInter; float dirD = v * vInter;
...@@ -85,22 +84,22 @@ bool intersectionLineConvexFace(typename PFP::MAP& map, Dart d, const typename P ...@@ -85,22 +84,22 @@ bool intersectionLineConvexFace(typename PFP::MAP& map, Dart d, const typename P
} }
template <typename PFP> template <typename PFP>
bool intersectionSegmentConvexFace(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& positions, const typename PFP::VEC3& PA, const typename PFP::VEC3& PB, typename PFP::VEC3& Inter) bool intersectionSegmentConvexFace(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position, const typename PFP::VEC3& PA, const typename PFP::VEC3& PB, typename PFP::VEC3& Inter)
{ {
typename PFP::VEC3 dir = PB - PA; typename PFP::VEC3 dir = PB - PA;
if (intersectionLineConvexFace(map,d,positions,PA,dir,Inter)) if (intersectionLineConvexFace(map, d, position, PA, dir, Inter))
{ {
typename PFP::VEC3 dirA = PA - Inter; typename PFP::VEC3 dirA = PA - Inter;
typename PFP::VEC3 dirB = PB -Inter; typename PFP::VEC3 dirB = PB - Inter;
if ( (dirA*dirB) < 0 ) if (dirA * dirB < 0)
return true; return true;
} }
return false; return false;
} }
template <typename PFP> template <typename PFP>
bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, const typename PFP::TVEC3& positions) bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, const typename PFP::TVEC3& position)
{ {
typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::VEC3 VEC3 ;
...@@ -109,8 +108,8 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co ...@@ -109,8 +108,8 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co
VEC3 tris2[3]; VEC3 tris2[3];
for (unsigned int i = 0; i < 3; ++i) for (unsigned int i = 0; i < 3; ++i)
{ {
tris1[i] = positions[tri1]; tris1[i] = position[tri1];
tris2[i] = positions[tri2]; tris2[i] = position[tri2];
tri1 = map.phi1(tri1); tri1 = map.phi1(tri1);
tri2 = map.phi1(tri2); tri2 = map.phi1(tri2);
} }
...@@ -167,8 +166,8 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co ...@@ -167,8 +166,8 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co
// return isSegmentInTriangle2D(inter1,inter2,tris2[0],tris2[1],triS2[2],nTri2); // return isSegmentInTriangle2D(inter1,inter2,tris2[0],tris2[1],triS2[2],nTri2);
//compute face normal //compute face normal
VEC3 normale1 = faceNormal<PFP>(map,tri1,positions); VEC3 normale1 = faceNormal<PFP>(map, tri1, position);
VEC3 bary1 = faceCentroid<PFP>(map,tri1,positions); VEC3 bary1 = faceCentroid<PFP>(map, tri1, position);
int pos = 0; int pos = 0;
int neg = 0; int neg = 0;
...@@ -188,8 +187,8 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co ...@@ -188,8 +187,8 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co
return false; return false;
//same for the second triangle //same for the second triangle
VEC3 normale2 = faceNormal<PFP>(map,tri2,positions); VEC3 normale2 = faceNormal<PFP>(map, tri2, position);
VEC3 bary2 = faceCentroid<PFP>(map,tri2,positions); VEC3 bary2 = faceCentroid<PFP>(map, tri2, position);
pos = 0; pos = 0;
neg = 0; neg = 0;
for (unsigned int i = 0; i < 3 ; ++i) for (unsigned int i = 0; i < 3 ; ++i)
...@@ -210,7 +209,7 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co ...@@ -210,7 +209,7 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co
for (unsigned int i = 0; i < 3 && !intersection; ++i) for (unsigned int i = 0; i < 3 && !intersection; ++i)
{ {
VEC3 inter; VEC3 inter;
intersection = Geom::intersectionSegmentTriangle(tris1[i],tris1[(i+1)%3],tris2[0],tris2[1],tris2[2],inter); intersection = Geom::intersectionSegmentTriangle(tris1[i], tris1[(i+1)%3], tris2[0], tris2[1], tris2[2], inter);
} }
if (intersection) if (intersection)
...@@ -219,14 +218,34 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co ...@@ -219,14 +218,34 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co
for (unsigned int i = 0; i < 3 && !intersection; ++i) for (unsigned int i = 0; i < 3 && !intersection; ++i)
{ {
VEC3 inter; VEC3 inter;
intersection = Geom::intersectionSegmentTriangle(tris2[i],tris2[(i+1)%3],tris1[0],tris1[1],tris1[2],inter); intersection = Geom::intersectionSegmentTriangle(tris2[i], tris2[(i+1)%3], tris1[0], tris1[1], tris1[2], inter);
} }
return intersection; return intersection;
} }
} template <typename PFP>
bool intersectionSphereEdge(typename PFP::MAP& map, typename PFP::VEC3& center, typename PFP::REAL radius, Dart d, const typename PFP::TVEC3& position, typename PFP::REAL& alpha)
{
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
const typename PFP::VEC3& p1 = position[d];
const typename PFP::VEC3& p2 = position[map.phi1(d)];
if(Geom::isPointInSphere(p1, center, radius) && !Geom::isPointInSphere(p2, center, radius))
{
VEC3 p = p1 - center;
VEC3 qminusp = p2 - center - p;
REAL s = p * qminusp;
REAL n2 = qminusp.norm2();
alpha = (- s + sqrt(s*s + n2 * (radius*radius - p.norm2()))) / n2;
return true ;
}
return false ;
} }
} } // namespace Geometry
} // namespace Algo
} // namespace CGoGN
...@@ -926,7 +926,7 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector ...@@ -926,7 +926,7 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector
// Allocate vertices // Allocate vertices
AttributeContainer& vxContainer = m_map.getAttributeContainer(VERTEX_CELL); AttributeContainer& vxContainer = m_map.getAttributeContainer(VERTEX);
std::vector<unsigned int> verticesId; std::vector<unsigned int> verticesId;
...@@ -971,10 +971,10 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector ...@@ -971,10 +971,10 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector
// Read positions // Read positions
AttributeHandler<typename PFP::VEC3> position = m_map.template getAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "position") ; AttributeHandler<typename PFP::VEC3> position = m_map.template getAttribute<typename PFP::VEC3>(VERTEX, "position") ;
if (!position.isValid()) if (!position.isValid())
position = m_map.template addAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "position") ; position = m_map.template addAttribute<typename PFP::VEC3>(VERTEX, "position") ;
attrNames.push_back(position.name()) ; attrNames.push_back(position.name()) ;
......
...@@ -40,10 +40,10 @@ namespace CGoGN ...@@ -40,10 +40,10 @@ namespace CGoGN
class CellMarkerGen class CellMarkerGen
{ {
protected: protected:
Mark m_mark; Mark m_mark ;
AttribMap& m_map; AttribMap& m_map ;
unsigned int m_cell; unsigned int m_cell ;
unsigned int m_thread; unsigned int m_thread ;
public: public:
/** /**
...@@ -55,7 +55,7 @@ public: ...@@ -55,7 +55,7 @@ public:
{ {
if(!map.isOrbitEmbedded(cell)) if(!map.isOrbitEmbedded(cell))
map.addEmbedding(cell) ; map.addEmbedding(cell) ;
m_mark = map.getNewMark(cell, thread); m_mark = map.getNewMark(cell, thread) ;
} }
virtual ~CellMarkerGen() virtual ~CellMarkerGen()
...@@ -74,11 +74,11 @@ public: ...@@ -74,11 +74,11 @@ public:
*/ */
virtual void mark(Dart d) virtual void mark(Dart d)
{ {
unsigned int a = m_map.getEmbedding(m_cell, d); unsigned int a = m_map.getEmbedding(m_cell, d) ;
if (a == EMBNULL) if (a == EMBNULL)
a = m_map.embedNewCell(m_cell, d); a = m_map.embedNewCell(m_cell, d) ;
m_map.getMarkVector(m_cell, m_thread)->operator[](a).setMark(m_mark); m_map.getMarkVector(m_cell, m_thread)->operator[](a).setMark(m_mark) ;
} }
/** /**
...@@ -86,11 +86,11 @@ public: ...@@ -86,11 +86,11 @@ public:
*/ */
virtual void unmark(Dart d) virtual void unmark(Dart d)
{ {
unsigned int a = m_map.getEmbedding(m_cell, d); unsigned int a = m_map.getEmbedding(m_cell, d) ;
if (a == EMBNULL) if (a == EMBNULL)
a = m_map.embedNewCell(m_cell, d); a = m_map.embedNewCell(m_cell, d) ;
m_map.getMarkVector(m_cell, m_thread)->operator[](a).unsetMark(m_mark); m_map.getMarkVector(m_cell, m_thread)->operator[](a).unsetMark(m_mark) ;
} }
/** /**
...@@ -98,11 +98,11 @@ public: ...@@ -98,11 +98,11 @@ public:
*/ */
virtual bool isMarked(Dart d) virtual bool isMarked(Dart d)
{ {
unsigned int a = m_map.getEmbedding(m_cell, d); unsigned int a = m_map.getEmbedding(m_cell, d) ;
if (a == EMBNULL) if (a == EMBNULL)
return false; return false ;
return m_map.getMarkVector(m_cell, m_thread)->operator[](a).testMark(m_mark); return m_map.getMarkVector(m_cell, m_thread)->operator[](a).testMark(m_mark) ;
} }
/** /**
...@@ -110,7 +110,7 @@ public: ...@@ -110,7 +110,7 @@ public:
*/ */
virtual void mark(unsigned int em) virtual void mark(unsigned int em)
{ {
m_map.getMarkVector(m_cell, m_thread)->operator[](em).setMark(m_mark); m_map.getMarkVector(m_cell, m_thread)->operator[](em).setMark(m_mark) ;
} }
/** /**
...@@ -118,7 +118,7 @@ public: ...@@ -118,7 +118,7 @@ public:
*/ */
virtual void unmark(unsigned int em) virtual void unmark(unsigned int em)
{ {
m_map.getMarkVector(m_cell, m_thread)->operator[](em).unsetMark(m_mark); m_map.getMarkVector(m_cell, m_thread)->operator[](em).unsetMark(m_mark) ;
} }
/** /**
...@@ -126,7 +126,7 @@ public: ...@@ -126,7 +126,7 @@ public:
*/ */
virtual bool isMarked(unsigned int em) virtual bool isMarked(unsigned int em)
{ {
return m_map.getMarkVector(m_cell, m_thread)->operator[](em).testMark(m_mark); return m_map.getMarkVector(m_cell, m_thread)->operator[](em).testMark(m_mark) ;
} }
/** /**
...@@ -136,7 +136,7 @@ public: ...@@ -136,7 +136,7 @@ public:
{ {
AttributeContainer& cont = m_map.getAttributeContainer(m_cell) ; AttributeContainer& cont = m_map.getAttributeContainer(m_cell) ;
for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i)) for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
m_map.getMarkVector(m_cell, m_thread)->operator[](i).setMark(m_mark); m_map.getMarkVector(m_cell, m_thread)->operator[](i).setMark(m_mark) ;
} }
/** /**
...@@ -199,7 +199,7 @@ public: ...@@ -199,7 +199,7 @@ public:
virtual ~CellMarkerStore() virtual ~CellMarkerStore()
{ {
unmarkAll() ; unmarkAll() ;
assert(isAllUnmarked()); assert(isAllUnmarked()) ;
} }
protected: protected:
...@@ -239,7 +239,7 @@ public: ...@@ -239,7 +239,7 @@ public:
virtual ~CellMarkerNoUnmark() virtual ~CellMarkerNoUnmark()
{ {
assert(isAllUnmarked()); assert(isAllUnmarked()) ;
} }
protected: protected:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment