Commit 2dbc138a authored by CGoGN GIT Supervisor's avatar CGoGN GIT Supervisor

Merge branch 'master' of /home/jund/CGoGN

* 'master' of /home/jund/CGoGN:
  correction intersectionPlaneRay et ajout d'un test de vérif
parents 9e310c04 51b5ef93
...@@ -43,7 +43,6 @@ add_executable( Geom_inclusionD ./Geom_inclusion.cpp) ...@@ -43,7 +43,6 @@ add_executable( Geom_inclusionD ./Geom_inclusion.cpp)
target_link_libraries( Geom_inclusionD target_link_libraries( Geom_inclusionD
${CGoGN_LIBS_D} ${COMMON_LIBS} ) ${CGoGN_LIBS_D} ${COMMON_LIBS} )
add_executable( Geom_intersectionD ./Geom_intersection.cpp)
#add_executable( Algo_Geom_inclusionD ./Algo_Geom_inclusion.cpp) target_link_libraries( Geom_intersectionD
#target_link_libraries( Algo_Geom_inclusionD ${CGoGN_LIBS_D} ${COMMON_LIBS} )
# containerD topologyD utilsD algoD ${COMMON_LIBS} )
#include <iostream>
#include <Geometry/intersection.h>
using namespace CGoGN;
int main()
{
typedef Geom::Vec3f VEC3;
std::cout << "Check Geometry/intersection.h" << std::endl;
std::cout << "Check Status : PARTIAL" << std::endl;
// enum Intersection
// {
// NO_INTERSECTION = 0,
// VERTEX_INTERSECTION = 1,
// EDGE_INTERSECTION = 2,
// FACE_INTERSECTION = 3
// } ;
// Intersection intersectionRayTriangle(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) ;
// Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter) ;
// Intersection intersectionSegmentTriangle(const VEC3& PA, const VEC3& PB, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter) ;
std::cout << "Check intersectPlaneRay : Start" << std::endl;
VEC3 p1(0,0,0);
VEC3 p2(5,0,0);
VEC3 p3(5,5,0);
VEC3 p4(5,10,0);
VEC3 p5(5,10,1);
VEC3 p6(10,13,13);
Geom::Plane3D<float> pl1(p1,p2,p3);
Geom::Plane3D<float> pl2(p3,p4,p5);
Geom::Plane3D<float> pl3(p3,p5,p6);
VEC3 res;
if(intersectionPlaneRay(pl1,p4,VEC3(0,1,0),res) == Geom::FACE_INTERSECTION) {
if(p4[0]!=res[0] || p4[1]!=res[1] || p4[2]!=res[2])
std::cout << "ERROR : intersectPlaneRay : point in plane (bad intersection point)" << std::endl;
}
else
std::cout << "ERROR : intersectPlaneRay : point in plane" << std::endl;
if(intersectionPlaneRay(pl1,p5,VEC3(0,0,-1),res) == Geom::FACE_INTERSECTION) {
if(p4[0]!=res[0] || p4[1]!=res[1] || p4[2]!=res[2])
std::cout << "ERROR : intersectPlaneRay : point/plane (bad intersection point)" << std::endl;
}
else
std::cout << "ERROR : intersectPlaneRay : point/plane" << std::endl;
if(intersectionPlaneRay(pl2,p1,VEC3(1,0,0),res) != Geom::FACE_INTERSECTION)
std::cout << "ERROR : intersectPlaneRay (1)" << std::endl;
if(intersectionPlaneRay(pl3,p1,VEC3(1,0,0),res) != Geom::FACE_INTERSECTION)
std::cout << "ERROR : intersectPlaneRay (2)" << std::endl;
if(intersectionPlaneRay(pl2,p1,VEC3(0,1,0),res) == Geom::FACE_INTERSECTION)
std::cout << "ERROR : intersectPlaneRay : ray parallel to plane" << std::endl;
if(intersectionPlaneRay(pl1,p5,VEC3(0,0,1),res) == Geom::FACE_INTERSECTION)
std::cout << "ERROR : intersectPlaneRay : point/plane" << std::endl;
std::cout << "Check intersectPlaneRay : Done" << std::endl;
// Intersection intersection2DSegmentSegment(const VEC3& PA, const VEC3& PB, const VEC3& QA, const VEC3& QB, VEC3& Inter) ;
return 0;
}
...@@ -16,33 +16,27 @@ namespace ExportPov ...@@ -16,33 +16,27 @@ namespace ExportPov
template <typename PFP> template <typename PFP>
void exportTriangleWire(std::ofstream& out,typename PFP::VEC3& p1,typename PFP::VEC3& p2,typename PFP::VEC3& p3) void exportTriangleWire(std::ofstream& out,typename PFP::VEC3& p1,typename PFP::VEC3& p2,typename PFP::VEC3& p3)
{ {
CGoGNout << "cylinder {" << CGoGNendl; out << "cylinder { <" << p1[0] << "," << p1[2] << "," << p1[1] << ">, <" << p2[0] << "," << p2[2] << "," << p2[1] << ">, 0.5 }" << std::endl;
CGoGNout << "<" << p1[0] << "," << p1[1] << "," << p1[2] << ">, <" << p2[0] << "," << p2[1] << "," << p2[2] << ">, 0.5" << CGoGNendl;
CGoGNout << "}" << CGoGNendl;
CGoGNout << "cylinder {" << CGoGNendl; out << "cylinder { <" << p1[0] << "," << p1[2] << "," << p1[1] << ">, <" << p3[0] << "," << p3[2] << "," << p3[1] << ">, 0.5 }" << std::endl;
CGoGNout << "<" << p1[0] << "," << p1[1] << "," << p1[2] << ">, <" << p3[0] << "," << p3[1] << "," << p3[2] << ">, 0.5" << CGoGNendl;
CGoGNout << "}" << CGoGNendl;
CGoGNout << "cylinder {" << CGoGNendl; out << "cylinder { <" << p3[0] << "," << p3[2] << "," << p3[1] << ">, <" << p2[0] << "," << p2[2] << "," << p2[1] << ">, 0.5 }" << std::endl;
CGoGNout << "<" << p3[0] << "," << p3[1] << "," << p3[2] << ">, <" << p2[0] << "," << p2[1] << "," << p2[2] << ">, 0.5" << CGoGNendl;
CGoGNout << "}" << CGoGNendl;
} }
template <typename PFP> template <typename PFP>
void exportTrianglePlain(std::ofstream& out,typename PFP::VEC3& p1,typename PFP::VEC3& p2,typename PFP::VEC3& p3) void exportTrianglePlain(std::ofstream& out,typename PFP::VEC3& p1,typename PFP::VEC3& p2,typename PFP::VEC3& p3)
{ {
CGoGNout << "triangle {" << CGoGNendl; out << "triangle {" << std::endl;
CGoGNout << "<" << p1[0] << "," << p1[1] << "," << p1[2] << ">," << CGoGNendl; out << "<" << p1[0] << "," << p1[2] << "," << p1[1] << ">," << std::endl;
CGoGNout << "<" << p2[0] << "," << p2[1] << "," << p2[2] << ">, " << CGoGNendl; out << "<" << p2[0] << "," << p2[2] << "," << p2[1] << ">, " << std::endl;
CGoGNout << "<" << p3[0] << "," << p3[1] << "," << p3[2] << "> " << CGoGNendl; out << "<" << p3[0] << "," << p3[2] << "," << p3[1] << "> " << std::endl;
CGoGNout << "}" << CGoGNendl; out << "}" << std::endl;
} }
template <typename PFP> template <typename PFP>
void exportMeshPlain(std::ofstream& out, typename PFP::MAP& map, typename PFP::TVEC3& position, const std::string& meshName, const FunctorSelect& good = SelectorTrue()) void exportMeshPlain(std::ofstream& out, typename PFP::MAP& map, typename PFP::TVEC3& position, const std::string& meshName, const FunctorSelect& good = SelectorTrue())
{ {
CGoGNout << "#declare " << meshName << "= union {" << CGoGNendl; out << "#declare " << meshName << "= union {" << std::endl;
DartMarkerStore traite(map); DartMarkerStore traite(map);
...@@ -60,25 +54,25 @@ void exportMeshPlain(std::ofstream& out, typename PFP::MAP& map, typename PFP::T ...@@ -60,25 +54,25 @@ void exportMeshPlain(std::ofstream& out, typename PFP::MAP& map, typename PFP::T
Algo::ExportPov::exportTrianglePlain<PFP>(out,position[dd],position[map.phi1(dd)],position[map.phi1(map.phi1(dd))]); Algo::ExportPov::exportTrianglePlain<PFP>(out,position[dd],position[map.phi1(dd)],position[map.phi1(map.phi1(dd))]);
} }
else { else {
CGoGNout << "polygon{ " << nb+1 << CGoGNendl; out << "polygon{ " << nb+1 << std::endl;
dd=d; dd=d;
do { do {
CGoGNout << "<" << position[dd][0] << "," << position[dd][1] << "," << position[dd][2] << ">," << CGoGNendl; out << "<" << position[dd][0] << "," << position[dd][2] << "," << position[dd][1] << ">," << std::endl;
dd = map.phi1(dd); dd = map.phi1(dd);
}while(dd!=d); }while(dd!=d);
CGoGNout << "<" << position[d][0] << "," << position[d][1] << "," << position[d][2] << ">" << CGoGNendl; out << "<" << position[d][0] << "," << position[d][2] << "," << position[d][1] << ">" << std::endl;
CGoGNout << "}" << CGoGNendl; out << "}" << std::endl;
} }
} }
} }
CGoGNout << "}" << CGoGNendl; out << "}" << std::endl;
} }
template <typename PFP> template <typename PFP>
void exportMeshWire(std::ofstream& out, typename PFP::MAP& map, typename PFP::TVEC3& position, const std::string& meshName, const FunctorSelect& good = SelectorTrue()) void exportMeshWire(std::ofstream& out, typename PFP::MAP& map, typename PFP::TVEC3& position, const std::string& meshName, const FunctorSelect& good = SelectorTrue())
{ {
CGoGNout << "#declare " << meshName << "= union {" << CGoGNendl; out << "#declare " << meshName << "= union {" << std::endl;
DartMarkerStore traite(map); DartMarkerStore traite(map);
...@@ -99,10 +93,10 @@ void exportMeshWire(std::ofstream& out, typename PFP::MAP& map, typename PFP::TV ...@@ -99,10 +93,10 @@ void exportMeshWire(std::ofstream& out, typename PFP::MAP& map, typename PFP::TV
dd=d; dd=d;
do { do {
if(position[dd][0]!=position[map.phi1(dd)][0] || position[dd][1]!=position[map.phi1(dd)][1] || position[dd][2]!=position[map.phi1(dd)][2]) { if(position[dd][0]!=position[map.phi1(dd)][0] || position[dd][1]!=position[map.phi1(dd)][1] || position[dd][2]!=position[map.phi1(dd)][2]) {
CGoGNout << "cylinder{ " << CGoGNendl; out << "cylinder{ " << std::endl;
CGoGNout << "<" << position[dd][0] << "," << position[dd][1] << "," << position[dd][2] << ">," << CGoGNendl; out << "<" << position[dd][0] << "," << position[dd][2] << "," << position[dd][1] << ">," << std::endl;
CGoGNout << "<" << position[map.phi1(dd)][0] << "," << position[map.phi1(dd)][1] << "," << position[map.phi1(dd)][2] << ">, 0.5" << CGoGNendl; out << "<" << position[map.phi1(dd)][0] << "," << position[map.phi1(dd)][2] << "," << position[map.phi1(dd)][1] << ">, 0.5" << std::endl;
CGoGNout << "}" << CGoGNendl; out << "}" << std::endl;
} }
dd = map.phi1(dd); dd = map.phi1(dd);
}while(dd!=d); }while(dd!=d);
...@@ -110,7 +104,7 @@ void exportMeshWire(std::ofstream& out, typename PFP::MAP& map, typename PFP::TV ...@@ -110,7 +104,7 @@ void exportMeshWire(std::ofstream& out, typename PFP::MAP& map, typename PFP::TV
} }
} }
CGoGNout << "}" << CGoGNendl; out << "}" << std::endl;
} }
template <typename PFP> template <typename PFP>
...@@ -127,27 +121,27 @@ bool exportScenePov(typename PFP::MAP& map, typename PFP::TVEC3& position, const ...@@ -127,27 +121,27 @@ bool exportScenePov(typename PFP::MAP& map, typename PFP::TVEC3& position, const
float angleZ = angle_Z; float angleZ = angle_Z;
//define the camera position //define the camera position
CGoGNout << "camera { location <" << cameraPos[0] << "," << cameraPos[1] << "," << cameraPos[2] << "> look_at <" << cameraLook[0] << "," << cameraLook[1] << "," << cameraLook[2] <<">}" << CGoGNendl;; out << "camera { location <" << cameraPos[0] << "," << cameraPos[1] << "," << cameraPos[2] << "> look_at <" << cameraLook[0] << "," << cameraLook[1] << "," << cameraLook[2] <<">}" << std::endl;
//set a "infinite" plane //set a "infinite" plane
// CGoGNout << "plane { y, -1 pigment { color rgb 1 } }" << CGoGNendl; // out << "plane { y, -1 pigment { color rgb 1 } }" << std::endl;
//set a sky sphere //set a sky sphere
CGoGNout << "sphere { <0, 0, 0>, 5000"; out << "sphere { <0, 0, 0>, 5000";
CGoGNout << "texture{ pigment { color rgb <1, 1, 1>} finish { ambient 1 diffuse 0 } } }" << CGoGNendl; out << "texture{ pigment { color rgb <1, 1, 1>} finish { ambient 1 diffuse 0 } } }" << std::endl;
//put some lights //put some lights
CGoGNout << "light_source { <" << cameraPos[0] << "," << cameraPos[1] << "," << cameraPos[2] << "> color rgb 0.45}" << CGoGNendl; out << "light_source { <" << cameraPos[0] << "," << cameraPos[1] << "," << cameraPos[2] << "> color rgb 0.45}" << std::endl;
// CGoGNout << "light_source { <-120, -300, -10> color rgb 0.25 }"<< CGoGNendl; // out << "light_source { <-120, -300, -10> color rgb 0.25 }"<< std::endl;
//set a high quality rendering //set a high quality rendering
CGoGNout << "global_settings {" << CGoGNendl; out << "global_settings {" << std::endl;
CGoGNout << "radiosity {" << CGoGNendl; out << "radiosity {" << std::endl;
CGoGNout << "pretrace_start 0.08 pretrace_end 0.04" << CGoGNendl; out << "pretrace_start 0.08 pretrace_end 0.04" << std::endl;
CGoGNout << "count 100 nearest_count 10 error_bound 0.15 recursion_limit 1 low_error_factor 0.2 gray_threshold 0.0 minimum_reuse 0.015 brightness 1 adc_bailout 0.01/2 normal off media off} max_trace_level 255}" << CGoGNendl; out << "count 100 nearest_count 10 error_bound 0.15 recursion_limit 1 low_error_factor 0.2 gray_threshold 0.0 minimum_reuse 0.015 brightness 1 adc_bailout 0.01/2 normal off media off} max_trace_level 255}" << std::endl;
Algo::ExportPov::exportMeshPlain<PFP>(out,map,position,"myMesh",good); Algo::ExportPov::exportMeshPlain<PFP>(out,map,position,"myMesh",good);
CGoGNout << "object {myMesh" << CGoGNendl; out << "object {myMesh" << std::endl;
CGoGNout << "translate <" << translate[0] << "," << translate[1] << "," << translate[2] << ">" << CGoGNendl; out << "translate <" << translate[0] << "," << translate[1] << "," << translate[2] << ">" << std::endl;
CGoGNout << "rotate <" << angleX << "," << angleY << "," << angleZ << "> " << CGoGNendl; out << "rotate <" << angleX << "," << angleY << "," << angleZ << "> " << std::endl;
CGoGNout << "texture{ pigment{ color rgb<1.0,1.0,1>} finish { ambient rgb 0.05 brilliance 0.5 } } }" << CGoGNendl; out << "texture{ pigment{ color rgb<1.0,1.0,1>} finish { ambient rgb 0.05 brilliance 0.5 } } }" << std::endl;
out.close(); out.close();
return true; return true;
......
...@@ -87,7 +87,7 @@ template <typename VEC3> ...@@ -87,7 +87,7 @@ template <typename VEC3>
Intersection intersectionSegmentTriangle(const VEC3& PA, const VEC3& PB, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter) ; Intersection intersectionSegmentTriangle(const VEC3& PA, const VEC3& PB, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter) ;
template <typename VEC3, typename PLANE3D> template <typename VEC3, typename PLANE3D>
Intersection intersectPlaneRay(const PLANE3D& pl,const VEC3& p1,const VEC3& dir, VEC3& Inter); Intersection intersectionPlaneRay(const PLANE3D& pl,const VEC3& p1,const VEC3& dir, VEC3& Inter);
template <typename VEC3> 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) ;
......
...@@ -149,7 +149,7 @@ Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VE ...@@ -149,7 +149,7 @@ Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VE
return VERTEX_INTERSECTION ; return VERTEX_INTERSECTION ;
} }
//inter with AB //inter with AB
CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AB" << CGoGNendl ; // CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AB" << CGoGNendl ;
return EDGE_INTERSECTION ; return EDGE_INTERSECTION ;
} }
if(oA == ALIGNED) if(oA == ALIGNED)
...@@ -163,7 +163,7 @@ Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VE ...@@ -163,7 +163,7 @@ Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VE
return VERTEX_INTERSECTION ; return VERTEX_INTERSECTION ;
} }
//inter with AC //inter with AC
CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AC" << CGoGNendl ; // CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AC" << CGoGNendl ;
return EDGE_INTERSECTION ; return EDGE_INTERSECTION ;
} }
if(oPBC == RIGHT) // same side of BC, test this edge if(oPBC == RIGHT) // same side of BC, test this edge
...@@ -179,7 +179,7 @@ Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VE ...@@ -179,7 +179,7 @@ Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VE
return VERTEX_INTERSECTION ; return VERTEX_INTERSECTION ;
} }
//inter with BC //inter with BC
CGoGNout << __FILE__ << " TODO compute edge coplanar intersection BC" << CGoGNendl ; // CGoGNout << __FILE__ << " TODO compute edge coplanar intersection BC" << CGoGNendl ;
return EDGE_INTERSECTION ; return EDGE_INTERSECTION ;
} }
...@@ -194,7 +194,7 @@ Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VE ...@@ -194,7 +194,7 @@ Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VE
return VERTEX_INTERSECTION ; return VERTEX_INTERSECTION ;
} }
//inter with AB //inter with AB
CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AB" << CGoGNendl ; // CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AB" << CGoGNendl ;
return EDGE_INTERSECTION ; return EDGE_INTERSECTION ;
} }
if(oPAB == ALIGNED) if(oPAB == ALIGNED)
...@@ -214,7 +214,7 @@ Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VE ...@@ -214,7 +214,7 @@ Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VE
return VERTEX_INTERSECTION ; return VERTEX_INTERSECTION ;
} }
//inter with AC //inter with AC
CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AC" << CGoGNendl ; // CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AC" << CGoGNendl ;
return EDGE_INTERSECTION ; return EDGE_INTERSECTION ;
} }
} }
...@@ -282,13 +282,27 @@ Intersection intersectionSegmentTriangle(const VEC3& PA, const VEC3& PB, const V ...@@ -282,13 +282,27 @@ Intersection intersectionSegmentTriangle(const VEC3& PA, const VEC3& PB, const V
// } // }
template <typename VEC3, typename PLANE3D> template <typename VEC3, typename PLANE3D>
Intersection intersectPlaneRay(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 isect = (pl.normal() * (pl.normal()*pl.d()-p1)) / (pl.normal()*dir); typename VEC3::DATA_TYPE denom = pl.normal()*dir;
if(denom==0)
{
if(pl.distance(p1)==0)
{
Inter = p1;
return FACE_INTERSECTION;
}
else
return NO_INTERSECTION;
}
typename VEC3::DATA_TYPE isect = ( pl.normal() * (pl.normal()*-1.0f*pl.d()-p1) ) / denom;
Inter = p1 + dir * isect;
if(0.0f <= isect) if(0.0f <= isect)
{ {
Inter = p1 + dir * isect;
return FACE_INTERSECTION; return FACE_INTERSECTION;
} }
......
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