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)
target_link_libraries( Geom_inclusionD
${CGoGN_LIBS_D} ${COMMON_LIBS} )
#add_executable( Algo_Geom_inclusionD ./Algo_Geom_inclusion.cpp)
#target_link_libraries( Algo_Geom_inclusionD
# containerD topologyD utilsD algoD ${COMMON_LIBS} )
add_executable( Geom_intersectionD ./Geom_intersection.cpp)
target_link_libraries( Geom_intersectionD
${CGoGN_LIBS_D} ${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
template <typename PFP>
void exportTriangleWire(std::ofstream& out,typename PFP::VEC3& p1,typename PFP::VEC3& p2,typename PFP::VEC3& p3)
{
CGoGNout << "cylinder {" << CGoGNendl;
CGoGNout << "<" << p1[0] << "," << p1[1] << "," << p1[2] << ">, <" << p2[0] << "," << p2[1] << "," << p2[2] << ">, 0.5" << CGoGNendl;
CGoGNout << "}" << CGoGNendl;
out << "cylinder { <" << p1[0] << "," << p1[2] << "," << p1[1] << ">, <" << p2[0] << "," << p2[2] << "," << p2[1] << ">, 0.5 }" << std::endl;
CGoGNout << "cylinder {" << CGoGNendl;
CGoGNout << "<" << p1[0] << "," << p1[1] << "," << p1[2] << ">, <" << p3[0] << "," << p3[1] << "," << p3[2] << ">, 0.5" << CGoGNendl;
CGoGNout << "}" << CGoGNendl;
out << "cylinder { <" << p1[0] << "," << p1[2] << "," << p1[1] << ">, <" << p3[0] << "," << p3[2] << "," << p3[1] << ">, 0.5 }" << std::endl;
CGoGNout << "cylinder {" << CGoGNendl;
CGoGNout << "<" << p3[0] << "," << p3[1] << "," << p3[2] << ">, <" << p2[0] << "," << p2[1] << "," << p2[2] << ">, 0.5" << CGoGNendl;
CGoGNout << "}" << CGoGNendl;
out << "cylinder { <" << p3[0] << "," << p3[2] << "," << p3[1] << ">, <" << p2[0] << "," << p2[2] << "," << p2[1] << ">, 0.5 }" << std::endl;
}
template <typename PFP>
void exportTrianglePlain(std::ofstream& out,typename PFP::VEC3& p1,typename PFP::VEC3& p2,typename PFP::VEC3& p3)
{
CGoGNout << "triangle {" << CGoGNendl;
CGoGNout << "<" << p1[0] << "," << p1[1] << "," << p1[2] << ">," << CGoGNendl;
CGoGNout << "<" << p2[0] << "," << p2[1] << "," << p2[2] << ">, " << CGoGNendl;
CGoGNout << "<" << p3[0] << "," << p3[1] << "," << p3[2] << "> " << CGoGNendl;
CGoGNout << "}" << CGoGNendl;
out << "triangle {" << std::endl;
out << "<" << p1[0] << "," << p1[2] << "," << p1[1] << ">," << std::endl;
out << "<" << p2[0] << "," << p2[2] << "," << p2[1] << ">, " << std::endl;
out << "<" << p3[0] << "," << p3[2] << "," << p3[1] << "> " << std::endl;
out << "}" << std::endl;
}
template <typename PFP>
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);
......@@ -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))]);
}
else {
CGoGNout << "polygon{ " << nb+1 << CGoGNendl;
out << "polygon{ " << nb+1 << std::endl;
dd=d;
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);
}while(dd!=d);
CGoGNout << "<" << position[d][0] << "," << position[d][1] << "," << position[d][2] << ">" << CGoGNendl;
CGoGNout << "}" << CGoGNendl;
out << "<" << position[d][0] << "," << position[d][2] << "," << position[d][1] << ">" << std::endl;
out << "}" << std::endl;
}
}
}
CGoGNout << "}" << CGoGNendl;
out << "}" << std::endl;
}
template <typename PFP>
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);
......@@ -99,10 +93,10 @@ void exportMeshWire(std::ofstream& out, typename PFP::MAP& map, typename PFP::TV
dd=d;
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]) {
CGoGNout << "cylinder{ " << CGoGNendl;
CGoGNout << "<" << position[dd][0] << "," << position[dd][1] << "," << position[dd][2] << ">," << CGoGNendl;
CGoGNout << "<" << position[map.phi1(dd)][0] << "," << position[map.phi1(dd)][1] << "," << position[map.phi1(dd)][2] << ">, 0.5" << CGoGNendl;
CGoGNout << "}" << CGoGNendl;
out << "cylinder{ " << std::endl;
out << "<" << position[dd][0] << "," << position[dd][2] << "," << position[dd][1] << ">," << std::endl;
out << "<" << position[map.phi1(dd)][0] << "," << position[map.phi1(dd)][2] << "," << position[map.phi1(dd)][1] << ">, 0.5" << std::endl;
out << "}" << std::endl;
}
dd = map.phi1(dd);
}while(dd!=d);
......@@ -110,7 +104,7 @@ void exportMeshWire(std::ofstream& out, typename PFP::MAP& map, typename PFP::TV
}
}
CGoGNout << "}" << CGoGNendl;
out << "}" << std::endl;
}
template <typename PFP>
......@@ -127,27 +121,27 @@ bool exportScenePov(typename PFP::MAP& map, typename PFP::TVEC3& position, const
float angleZ = angle_Z;
//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
// CGoGNout << "plane { y, -1 pigment { color rgb 1 } }" << CGoGNendl;
// out << "plane { y, -1 pigment { color rgb 1 } }" << std::endl;
//set a sky sphere
CGoGNout << "sphere { <0, 0, 0>, 5000";
CGoGNout << "texture{ pigment { color rgb <1, 1, 1>} finish { ambient 1 diffuse 0 } } }" << CGoGNendl;
out << "sphere { <0, 0, 0>, 5000";
out << "texture{ pigment { color rgb <1, 1, 1>} finish { ambient 1 diffuse 0 } } }" << std::endl;
//put some lights
CGoGNout << "light_source { <" << cameraPos[0] << "," << cameraPos[1] << "," << cameraPos[2] << "> color rgb 0.45}" << CGoGNendl;
// CGoGNout << "light_source { <-120, -300, -10> color rgb 0.25 }"<< CGoGNendl;
out << "light_source { <" << cameraPos[0] << "," << cameraPos[1] << "," << cameraPos[2] << "> color rgb 0.45}" << std::endl;
// out << "light_source { <-120, -300, -10> color rgb 0.25 }"<< std::endl;
//set a high quality rendering
CGoGNout << "global_settings {" << CGoGNendl;
CGoGNout << "radiosity {" << CGoGNendl;
CGoGNout << "pretrace_start 0.08 pretrace_end 0.04" << CGoGNendl;
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 << "global_settings {" << std::endl;
out << "radiosity {" << std::endl;
out << "pretrace_start 0.08 pretrace_end 0.04" << std::endl;
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);
CGoGNout << "object {myMesh" << CGoGNendl;
CGoGNout << "translate <" << translate[0] << "," << translate[1] << "," << translate[2] << ">" << CGoGNendl;
CGoGNout << "rotate <" << angleX << "," << angleY << "," << angleZ << "> " << CGoGNendl;
CGoGNout << "texture{ pigment{ color rgb<1.0,1.0,1>} finish { ambient rgb 0.05 brilliance 0.5 } } }" << CGoGNendl;
out << "object {myMesh" << std::endl;
out << "translate <" << translate[0] << "," << translate[1] << "," << translate[2] << ">" << std::endl;
out << "rotate <" << angleX << "," << angleY << "," << angleZ << "> " << std::endl;
out << "texture{ pigment{ color rgb<1.0,1.0,1>} finish { ambient rgb 0.05 brilliance 0.5 } } }" << std::endl;
out.close();
return true;
......
......@@ -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) ;
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>
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
return VERTEX_INTERSECTION ;
}
//inter with AB
CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AB" << CGoGNendl ;
// CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AB" << CGoGNendl ;
return EDGE_INTERSECTION ;
}
if(oA == ALIGNED)
......@@ -163,7 +163,7 @@ Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VE
return VERTEX_INTERSECTION ;
}
//inter with AC
CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AC" << CGoGNendl ;
// CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AC" << CGoGNendl ;
return EDGE_INTERSECTION ;
}
if(oPBC == RIGHT) // same side of BC, test this edge
......@@ -179,7 +179,7 @@ Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VE
return VERTEX_INTERSECTION ;
}
//inter with BC
CGoGNout << __FILE__ << " TODO compute edge coplanar intersection BC" << CGoGNendl ;
// CGoGNout << __FILE__ << " TODO compute edge coplanar intersection BC" << CGoGNendl ;
return EDGE_INTERSECTION ;
}
......@@ -194,7 +194,7 @@ Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VE
return VERTEX_INTERSECTION ;
}
//inter with AB
CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AB" << CGoGNendl ;
// CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AB" << CGoGNendl ;
return EDGE_INTERSECTION ;
}
if(oPAB == ALIGNED)
......@@ -214,7 +214,7 @@ Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VE
return VERTEX_INTERSECTION ;
}
//inter with AC
CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AC" << CGoGNendl ;
// CGoGNout << __FILE__ << " TODO compute edge coplanar intersection AC" << CGoGNendl ;
return EDGE_INTERSECTION ;
}
}
......@@ -282,13 +282,27 @@ Intersection intersectionSegmentTriangle(const VEC3& PA, const VEC3& PB, const V
// }
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)
{
Inter = p1 + dir * isect;
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