Commit d5fb424d authored by Pierre Kraemer's avatar Pierre Kraemer

mise en forme

parent 5b625afc
#ifndef PARTCELL_H
#define PARTCELL_H
#include "particle_base.h"
#include "Algo/MovingObjects/particle_base.h"
#include "Algo/Geometry/inclusion.h"
#include "Algo/Geometry/plane.h"
#include "Geometry/intersection.h"
#include "Geometry/orientation.h"
#include <iostream>
......@@ -20,7 +21,8 @@ namespace Algo
namespace MovingObjects
{
enum {
enum
{
NO_CROSS,
CROSS_EDGE,
CROSS_OTHER
......@@ -45,15 +47,19 @@ public :
unsigned int crossCell ;
float distance;
ParticleCell2DAndHalf(Map& map) : m(map)
{}
ParticleCell2DAndHalf(Map& map, Dart belonging_cell, VEC3 pos, const TAB_POS& tabPos) :
ParticleBase(pos), m(map), m_positions(tabPos), d(belonging_cell), lastCrossed(belonging_cell), state(FACE), crossCell(NO_CROSS)
ParticleBase(pos), m(map), m_positions(tabPos), d(belonging_cell), lastCrossed(belonging_cell), state(FACE), crossCell(NO_CROSS), distance(0)
{}
Dart getCell() { return d; }
float getDistance() { return distance; }
Geom::Orientation3D getOrientationEdge(const VEC3& point, Dart d);
void display();
......@@ -77,28 +83,29 @@ public :
void move(const VEC3& newCurrent)
{
distance = 0 ;
crossCell = NO_CROSS ;
if(!Geom::arePointsEquals(newCurrent, m_position))
{
switch(state) {
case VERTEX : vertexState(newCurrent); break;
case EDGE : edgeState(newCurrent); break;
case FACE : faceState(newCurrent); break;
case VERTEX : vertexState(newCurrent); break;
case EDGE : edgeState(newCurrent); break;
case FACE : faceState(newCurrent); break;
}
display();
// display();
}
else
m_position = newCurrent;
}
};
#include "particle_cell_2DandHalf.hpp"
} // namespace MovingObjects
}
} // namespace Algo
}
} // namespace CGoGN
}
#include "Algo/MovingObjects/particle_cell_2DandHalf.hpp"
#endif
//#define DEBUG
namespace CGoGN
{
namespace Algo
{
namespace MovingObjects
{
template <typename PFP>
void ParticleCell2DAndHalf<PFP>::display()
{
......@@ -11,23 +20,23 @@ void ParticleCell2DAndHalf<PFP>::display()
template <typename PFP>
typename PFP::VEC3 ParticleCell2DAndHalf<PFP>::pointInFace(Dart d)
{
const VEC3& p1(m_positions[d]);
Dart dd=m.phi1(d);
const VEC3& p2(m_positions[dd]);
dd=m.phi1(dd);
VEC3& p3(m_positions[dd]);
const VEC3& p1(m_positions[d]) ;
Dart dd = m.phi1(d) ;
const VEC3& p2(m_positions[dd]) ;
dd = m.phi1(dd) ;
VEC3& p3(m_positions[dd]) ;
VEC3 v1(p2-p1);
VEC3 v1(p2 - p1) ;
while((v1^VEC3(p3-p1)).norm2()==0.0f)
while ((v1 ^ VEC3(p3 - p1)).norm2() == 0.0f)
{
dd = m.phi1(dd);
p3 = m_positions[dd];
dd = m.phi1(dd) ;
p3 = m_positions[dd] ;
}
CGoGNout << "pointInFace " << (p1+p3)*0.5f << CGoGNendl;
CGoGNout << "pointInFace " << (p1 + p3) * 0.5f << CGoGNendl ;
return (p1+p3)*0.5f;
return (p1 + p3) * 0.5f ;
}
template <typename PFP>
......@@ -36,10 +45,10 @@ Geom::Orientation3D ParticleCell2DAndHalf<PFP>::getOrientationEdge(const VEC3& p
const VEC3& endPoint = m_positions[m.phi2(d)];
const VEC3& vertexPoint = m_positions[d];
const VEC3& n1 = Algo::Geometry::faceNormal<PFP>(m,d,m_positions);
const VEC3& n1 = Algo::Geometry::faceNormal<PFP>(m, d, m_positions);
//orientation relative to the plane orthogonal to the face going through the edge
return Geom::testOrientation3D(point,vertexPoint, endPoint, vertexPoint+n1);
return Geom::testOrientation3D(point, vertexPoint, endPoint, vertexPoint+n1);
}
template <typename PFP>
......@@ -50,9 +59,9 @@ typename PFP::VEC3 ParticleCell2DAndHalf<PFP>::intersectLineEdge(const VEC3& pA,
VEC3 Inter;
VEC3 n1 = Algo::Geometry::faceNormal<PFP>(m,d,m_positions);
VEC3 n = (q2-q1) ^ n1 ;
VEC3 n = (q2 - q1) ^ n1 ;
Geom::intersectionLinePlane(pA,pB-pA,q1,n,Inter);
Geom::intersectionLinePlane(pA, pB - pA, q1, n, Inter) ;
Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(m,d,m_positions);
pl.project(Inter);
......@@ -65,7 +74,7 @@ Geom::Orientation3D ParticleCell2DAndHalf<PFP>::getOrientationFace(VEC3 point, V
{
const VEC3& dPoint = m_positions[d];
VEC3 n1 = Algo::Geometry::faceNormal<PFP>(m,d,m_positions);
VEC3 n1 = Algo::Geometry::faceNormal<PFP>(m, d, m_positions);
return Geom::testOrientation3D(point, sourcePoint, dPoint+n1, dPoint);
}
......@@ -221,14 +230,14 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
assert(std::isfinite(current[0]) && std::isfinite(current[1]) && std::isfinite(current[2]));
// assert(Algo::Geometry::isPointInConvexFace2D<PFP>(m,d,m_positions,m_position,true));
//project current within plane
//project current within face plane
VEC3 n1 = Algo::Geometry::faceNormal<PFP>(m,d,m_positions);
VEC3 n2 = current-m_position;
n1.normalize();
VEC3 n3 = n1^n2;
VEC3 n2 = current - m_position;
// n1.normalize();
VEC3 n3 = n1 ^ n2;
n3.normalize();
VEC3 n4 = n3^n1;
current = m_position+(n2*n4)*n4;
VEC3 n4 = n3 ^ n1;
current = m_position + (n2 * n4) * n4;
//track new position within map
Dart dd = d;
......@@ -327,7 +336,7 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
{
case Geom::UNDER :
m_position = current;
state = FACE;;
state = FACE;
break;
default :
if(wsoe == Geom::ON)
......@@ -349,3 +358,9 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
}
}
}
} // namespace MovingObjects
} // namespace Algo
} // namespace CGoGN
......@@ -43,7 +43,6 @@ enum Intersection
FACE_INTERSECTION = 3
} ;
/**
* test the intersection between a line and a triangle
* @param P a point on the line
......@@ -54,9 +53,7 @@ enum Intersection
* @return the intersection ( FACE_INTERSECTION = OK, EDGE_INTERSECTION = line inside of plane)
*/
template <typename VEC3>
Intersection intersectionLinePlane(const VEC3& P, const VEC3& Dir, const VEC3& PlaneP, const VEC3& NormP, VEC3& Inter) ;
Intersection intersectionLinePlane(const VEC3& P, const VEC3& Dir, const VEC3& PlaneP, const VEC3& NormP, VEC3& Inter) ;
/**
* test the intersection between a ray and a triangle (optimized version with triple product
......@@ -84,8 +81,6 @@ Intersection intersectionRayTriangle(const VEC3& P, const VEC3& Dir, const VEC3&
template <typename VEC3>
Intersection intersectionRayTriangleOpt(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter);
/**
* test the intersection between a ray and a triangle (optimized version with triple product
* @param P a point on the line
......@@ -98,7 +93,6 @@ Intersection intersectionRayTriangleOpt(const VEC3& P, const VEC3& Dir, const VE
template <typename VEC3>
Intersection intersectionRayTriangleOpt(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc);
/**
* test the intersection between a ray and a triangle, but test only face intersection and
* @param P a point on the line
......
......@@ -28,32 +28,30 @@ namespace CGoGN
namespace Geom
{
template <typename VEC3>
Intersection intersectionLinePlane(const VEC3& P, const VEC3& Dir, const VEC3& PlaneP, const VEC3& NormP, VEC3& Inter)
Intersection intersectionLinePlane(const VEC3& P, const VEC3& Dir, const VEC3& PlaneP, const VEC3& NormP, VEC3& Inter)
{
float b = NormP * Dir;
float b = NormP * Dir ;
#define PRECISION 1e-20
if(fabs(b) < PRECISION) //ray parallel to triangle
#define PRECISION 1e-20
if (fabs(b) < PRECISION) //ray parallel to triangle
{
VEC3 v= PlaneP - P;
float c = NormP * v;
if(fabs(c) < PRECISION)
return EDGE_INTERSECTION;
VEC3 v = PlaneP - P ;
float c = NormP * v ;
if (fabs(c) < PRECISION )
return EDGE_INTERSECTION ;
return NO_INTERSECTION ;
}
#undef PRECISION
#undef PRECISION
float a = NormP * (PlaneP - P);
float a = NormP * (PlaneP - P) ;
Inter = P + (a/b)*Dir;
return FACE_INTERSECTION;
Inter = P + (a / b) * Dir ;
return FACE_INTERSECTION ;
}
template <typename VEC3>
Intersection intersectionRayTriangleOpt(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter)
Intersection intersectionRayTriangleOpt(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter)
{
typedef typename VEC3::DATA_TYPE T ;
......@@ -65,33 +63,32 @@ Intersection intersectionRayTriangleOpt(const VEC3& P, const VEC3& Dir, const VE
T y = tripleProduct(Dir, v, w) ;
T z = tripleProduct(Dir, w, u) ;
unsigned int np=0;
unsigned int nn=0;
unsigned int nz=0;
unsigned int np = 0 ;
unsigned int nn = 0 ;
unsigned int nz = 0 ;
if (x>T(0))
++np;
if (x > T(0))
++np ;
else if (x < T(0))
++nn ;
else
if (x<T(0))
++nn;
else ++nz;
++nz ;
if (y>T(0))
++np;
if (y > T(0))
++np ;
else if (y < T(0))
++nn ;
else
if (y<T(0))
++nn;
else ++nz;
++nz ;
if (z>T(0))
++np;
if (z > T(0))
++np ;
else if (z < T(0))
++nn ;
else
if (z<T(0))
++nn;
else ++nz;
++nz ;
if ((np !=0) && (nn!=0))
return NO_INTERSECTION;
if ((np != 0) && (nn != 0)) return NO_INTERSECTION ;
T sum = x + y + z ;
T alpha = y / sum ;
......@@ -99,15 +96,11 @@ Intersection intersectionRayTriangleOpt(const VEC3& P, const VEC3& Dir, const VE
T gamma = T(1) - alpha - beta ;
Inter = Ta * alpha + Tb * beta + Tc * gamma ;
return Intersection(FACE_INTERSECTION-nz);
return Intersection(FACE_INTERSECTION - nz) ;
}
template <typename VEC3>
Intersection intersectionRayTriangleOpt(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc)
Intersection intersectionRayTriangleOpt(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc)
{
typedef typename VEC3::DATA_TYPE T ;
......@@ -119,41 +112,38 @@ Intersection intersectionRayTriangleOpt(const VEC3& P, const VEC3& Dir, const VE
T y = tripleProduct(Dir, v, w) ;
T z = tripleProduct(Dir, w, u) ;
unsigned int np=0;
unsigned int nn=0;
unsigned int nz=0;
unsigned int np = 0 ;
unsigned int nn = 0 ;
unsigned int nz = 0 ;
if (x>T(0))
++np;
if (x > T(0))
++np ;
else if (x < T(0))
++nn ;
else
if (x<T(0))
++nn;
else ++nz;
++nz ;
if (y>T(0))
++np;
if (y > T(0))
++np ;
else if (y < T(0))
++nn ;
else
if (y<T(0))
++nn;
else ++nz;
++nz ;
if (z>T(0))
++np;
if (z > T(0))
++np ;
else if (z < T(0))
++nn ;
else
if (z<T(0))
++nn;
else ++nz;
++nz ;
if ((np !=0) && (nn!=0))
return NO_INTERSECTION;
return Intersection(FACE_INTERSECTION-nz);
if ((np != 0) && (nn != 0)) return NO_INTERSECTION ;
return Intersection(FACE_INTERSECTION - nz) ;
}
template <typename VEC3>
Intersection intersectionRayTriangle(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter)
Intersection intersectionRayTriangle(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter)
{
typedef typename VEC3::DATA_TYPE T ;
......@@ -190,7 +180,7 @@ Intersection intersectionRayTriangle(const VEC3& P, const VEC3& Dir, const VEC3&
template <typename VEC3>
Intersection intersectionLineTriangle(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter)
Intersection intersectionLineTriangle(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter)
{
typedef typename VEC3::DATA_TYPE T ;
......@@ -408,48 +398,48 @@ Intersection intersectionSegmentTriangle(const VEC3& PA, const VEC3& PB, const V
// }
template <typename VEC3, typename PLANE3D>
Intersection intersectionPlaneRay(const PLANE3D& pl,const VEC3& p1,const VEC3& dir, VEC3& Inter)
Intersection intersectionPlaneRay(const PLANE3D& pl, const VEC3& p1, const VEC3& dir, VEC3& Inter)
{
typename VEC3::DATA_TYPE denom = pl.normal()*dir;
if(denom==0)
if (denom == 0)
{
if(pl.distance(p1)==0)
if (pl.distance(p1) == 0)
{
Inter = p1;
return FACE_INTERSECTION;
Inter = p1 ;
return FACE_INTERSECTION ;
}
else
return NO_INTERSECTION;
return NO_INTERSECTION ;
}
typename VEC3::DATA_TYPE isect = ( pl.normal() * (pl.normal()*-1.0f*pl.d()-p1) ) / denom;
typename VEC3::DATA_TYPE isect = (pl.normal() * (pl.normal() * -1.0f * pl.d() - p1)) / denom ;
Inter = p1 + dir * isect;
Inter = p1 + dir * isect ;
if(0.0f <= isect)
if (0.0f <= isect)
{
return FACE_INTERSECTION;
return FACE_INTERSECTION ;
}
return NO_INTERSECTION;
}
template <typename VEC3>
Intersection intersection2DSegmentSegment(const VEC3& PA, const VEC3& PB, const VEC3& QA, const VEC3& QB, VEC3& Inter)
Intersection intersection2DSegmentSegment(const VEC3& PA, const VEC3& PB, const VEC3& QA, const VEC3& QB, VEC3& Inter)
{
typedef typename VEC3::DATA_TYPE T ;
VEC3 vp1p2 = PB - PA;
VEC3 vq1q2 = QB - QA;
VEC3 vp1q1 = QA - PA;
T delta = vp1p2[0]*vq1q2[1]- vp1p2[1]*vq1q2[0];
T coeff = vp1q1[0]*vq1q2[1]- vp1q1[1]*vq1q2[0];
T delta = vp1p2[0] * vq1q2[1] - vp1p2[1] * vq1q2[0] ;
T coeff = vp1q1[0] * vq1q2[1] - vp1q1[1] * vq1q2[0] ;
if(delta==0) //parallel
if (delta == 0) //parallel
{
//test if collinear
if(coeff==0)
if (coeff == 0)
{
//collinear
//TODO : check if there is a common point between the two edges
......@@ -460,18 +450,18 @@ Intersection intersection2DSegmentSegment(const VEC3& PA, const VEC3& PB, const
return NO_INTERSECTION;
}
else
Inter = VEC3((PA[0]*delta+vp1p2[0]*coeff)/delta,(PA[1]*delta+vp1p2[1]*coeff)/delta,(PA[2]*delta+vp1p2[2]*coeff)/delta);
Inter = VEC3((PA[0] * delta + vp1p2[0] * coeff) / delta, (PA[1] * delta + vp1p2[1] * coeff) / delta, (PA[2] * delta + vp1p2[2] * coeff) / delta) ;
//test if inter point is outside the edges
if(
(Inter[0]<PA[0] && Inter[0]<PB[0]) || (Inter[0]>PA[0] && Inter[0]>PB[0]) ||
(Inter[0]<QA[0] && Inter[0]<QB[0]) || (Inter[0]>QA[0] && Inter[0]>QB[0]) ||
(Inter[1]<PA[1] && Inter[1]<PB[1]) || (Inter[1]>PA[1] && Inter[1]>PB[1]) ||
(Inter[1]<QA[1] && Inter[1]<QB[1]) || (Inter[1]>QA[1] && Inter[1]>QB[1])
(Inter[0] < PA[0] && Inter[0] < PB[0]) || (Inter[0] > PA[0] && Inter[0] > PB[0]) ||
(Inter[0] < QA[0] && Inter[0] < QB[0]) || (Inter[0] > QA[0] && Inter[0] > QB[0]) ||
(Inter[1] < PA[1] && Inter[1] < PB[1]) || (Inter[1] > PA[1] && Inter[1] > PB[1]) ||
(Inter[1] < QA[1] && Inter[1] < QB[1]) || (Inter[1] > QA[1] && Inter[1] > QB[1])
)
return NO_INTERSECTION;
if(Geom::arePointsEquals(PA,Inter) || Geom::arePointsEquals(PB,Inter) || Geom::arePointsEquals(QA,Inter) || Geom::arePointsEquals(QB,Inter))
if(Geom::arePointsEquals(PA, Inter) || Geom::arePointsEquals(PB, Inter) || Geom::arePointsEquals(QA, Inter) || Geom::arePointsEquals(QB, Inter))
return VERTEX_INTERSECTION;
return EDGE_INTERSECTION;
......
......@@ -72,7 +72,7 @@ template <typename VEC3>
Orientation3D testOrientation3D(const VEC3& P, const VEC3& A, const VEC3& B, const VEC3& C)
{
typedef typename VEC3::DATA_TYPE T ;
Geom::Plane3D<T> plane(A,B,C) ;
Geom::Plane3D<T> plane(A, B, C) ;
return plane.orient(P) ;
}
......@@ -87,7 +87,7 @@ template <typename VEC3>
Orientation3D testOrientation3D(const VEC3& P, const VEC3& N, const VEC3& PP)
{
typedef typename VEC3::DATA_TYPE T ;
Geom::Plane3D<T> plane(N,PP) ;
Geom::Plane3D<T> plane(N, PP) ;
return plane.orient(P) ;
}
......
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