Commit 4830f7f3 authored by Sylvain Thery's avatar Sylvain Thery

forgottent commited files for MR & new orbits

parent 10aeeaff
......@@ -72,3 +72,9 @@ QT4_WRAP_CPP( clipping_moc ../clipping.h )
add_executable( clippingD ../clipping.cpp ${clipping_ui} ${clipping_moc})
target_link_libraries( clippingD
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
QT4_WRAP_UI( volumeExplorer_ui ../volumeExplorer.ui )
QT4_WRAP_CPP( volumeExplorer_moc ../volumeExplorer.h )
add_executable( volumeExplorerD ../volumeExplorer.cpp ${volumeExplorer_ui} ${volumeExplorer_moc})
target_link_libraries( volumeExplorerD
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
\ No newline at end of file
......@@ -64,3 +64,10 @@ QT4_WRAP_CPP( clipping_moc ../clipping.h )
add_executable( clipping ../clipping.cpp ${clipping_ui} ${clipping_moc})
target_link_libraries( clipping
${CGoGN_LIBS_R} ${CGoGN_EXT_LIBS} )
QT4_WRAP_UI( volumeExplorer_ui ../volumeExplorer.ui )
QT4_WRAP_CPP( volumeExplorer_moc ../volumeExplorer.h )
add_executable( volumeExplorer ../volumeExplorer.cpp ${volumeExplorer_ui} ${volumeExplorer_moc})
target_link_libraries( volumeExplorer
${CGoGN_LIBS_R} ${CGoGN_EXT_LIBS} )
\ No newline at end of file
......@@ -37,9 +37,9 @@ SimpleGMap3::SimpleGMap3()
Algo::Modelisation::Primitive3D<PFP> primCat(myMap,position);
Dart d = primCat.hexaGrid_topo(3,1,1);
primCat.embedHexaGrid(2,1,1);
std::cout << "AAA"<< std::endl;
myMap.check();
std::cout << "AAA"<< std::endl;
DartMarker markOrient(myMap);
std::vector<Dart> orient;
FunctorStore fs(orient);
......@@ -47,11 +47,13 @@ SimpleGMap3::SimpleGMap3()
d = 49;
myMap.foreach_dart_of_oriented_volume(d, fs);
std::cout << "AAA"<< std::endl;
for(std::vector<Dart>::iterator it = orient.begin() ; it != orient.end() ; ++it)
markOrient.mark(*it);
SelectorMarked sm(markOrient);
std::cout << "AAA"<< std::endl;
Algo::Modelisation::catmullClarkVol<PFP,PFP::TVEC3,PFP::VEC3>(myMap, position, sm);
for(unsigned int i = position.begin() ; i != position.end() ; position.next(i))
......@@ -86,6 +88,7 @@ SimpleGMap3::SimpleGMap3()
myMap.unsewVolumes(d);
myMap.check();
}
void SimpleGMap3::initGUI()
......
......@@ -53,6 +53,12 @@ add_executable( tuto5 tuto5.cpp ${tuto5_ui} ${tuto5_moc})
target_link_libraries( tuto5
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
QT4_WRAP_UI( tuto_orbits_ui tuto_orbits.ui )
QT4_WRAP_CPP(tuto_orbits_moc tuto_orbits.h)
add_executable( tuto_orbits tuto_orbits.cpp ${tuto_orbits_ui} ${tuto_orbits_moc})
target_link_libraries( tuto_orbits
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
#add_executable( tuto_subdivision tuto_subdivision.cpp)
#target_link_libraries( tuto_subdivision
......
......@@ -55,67 +55,94 @@ int main(int argc, char **argv)
return app.exec();
}
Dart xd1;
void MyQT::traverseMap()
{
DartMarker m1(myMap);
DartMarker m2(myMap);
myMap.rdfi(myMap.begin(),m1,m2);
//traverse cells of map using topological markers on darts
CGoGNout << "Traverse with DartMarkers:"<< CGoGNendl;
DartMarker dmV(myMap);
DartMarker dmE(myMap);
DartMarker dmF(myMap);
for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d))
{
if (!dmV.isMarked(d))
{
CGoGNout << "Vertex of dart "<<d<<CGoGNendl;
dmV.markOrbit(VERTEX,d);
}
if (!dmE.isMarked(d))
{
CGoGNout << "Edgee of dart "<<d<<CGoGNendl;
dmE.markOrbit(EDGE,d);
}
if (!dmF.isMarked(d))
{
CGoGNout << "Face of dart "<<d<<CGoGNendl;
dmF.markOrbit(FACE,d);
}
}
m1.unmarkAll();
m1.markOrbit(VOLUME,xd1);
// traverses cells of map with markers on embedded cells.
// More efficients but more memory costly if cells are not already embedded.
// Avoid using construction of objects not ell embedded
// render the topo of the map without boundary darts
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f,nb);
CGoGNout << "========================="<< CGoGNendl;
CGoGNout << "Traverse with CellMarkers:"<< CGoGNendl;
CellMarker cmV(myMap,VERTEX);
CellMarker cmE(myMap,EDGE);
CellMarker cmF(myMap,FACE);
for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d))
{
if (!cmV.isMarked(d))
{
CGoGNout << "Vertex of dart "<<d<<CGoGNendl;
cmV.mark(d);
}
if (!cmE.isMarked(d))
if (m2.isMarked(d))
{
CGoGNout << "Edgee of dart "<<d<<CGoGNendl;
cmE.mark(d);
m_render_topo->setDartColor(d,1.0f,0.0f,0.0f);
}
if (!cmF.isMarked(d))
if (m1.isMarked(d))
{
CGoGNout << "Face of dart "<<d<<CGoGNendl;
cmF.mark(d);
m_render_topo->setDartColor(d,0.0f,1.0f,0.0f);
}
}
// markers are cleaned and released at destruction of DartMarkers & CellMarkers
// DartMarkerStore should be used if few darts are traversed
// DartMarkerNoUnmark can be use if you want to manage unmarking yourself
//
//
// //traverse cells of map using topological markers on darts
//
// CGoGNout << "Traverse with DartMarkers:"<< CGoGNendl;
// DartMarker dmV(myMap);
// DartMarker dmE(myMap);
// DartMarker dmF(myMap);
// for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d))
// {
// if (!dmV.isMarked(d))
// {
// CGoGNout << "Vertex of dart "<<d<<CGoGNendl;
// dmV.markOrbit(VERTEX,d);
// }
// if (!dmE.isMarked(d))
// {
// CGoGNout << "Edgee of dart "<<d<<CGoGNendl;
// dmE.markOrbit(EDGE,d);
// }
// if (!dmF.isMarked(d))
// {
// CGoGNout << "Face of dart "<<d<<CGoGNendl;
// dmF.markOrbit(FACE,d);
// }
// }
//
//
// // traverses cells of map with markers on embedded cells.
// // More efficients but more memory costly if cells are not already embedded.
// // Avoid using construction of objects not ell embedded
//
// CGoGNout << "========================="<< CGoGNendl;
// CGoGNout << "Traverse with CellMarkers:"<< CGoGNendl;
// CellMarker cmV(myMap,VERTEX);
// CellMarker cmE(myMap,EDGE);
// CellMarker cmF(myMap,FACE);
// for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d))
// {
// if (!cmV.isMarked(d))
// {
// CGoGNout << "Vertex of dart "<<d<<CGoGNendl;
// cmV.mark(d);
// }
// if (!cmE.isMarked(d))
// {
// CGoGNout << "Edgee of dart "<<d<<CGoGNendl;
// cmE.mark(d);
// }
// if (!cmF.isMarked(d))
// {
// CGoGNout << "Face of dart "<<d<<CGoGNendl;
// cmF.mark(d);
// }
// }
//
// // markers are cleaned and released at destruction of DartMarkers & CellMarkers
// // DartMarkerStore should be used if few darts are traversed
// // DartMarkerNoUnmark can be use if you want to manage unmarking yourself
}
......@@ -123,19 +150,46 @@ void MyQT::traverseMap()
void MyQT::createMap()
{
Dart d1 = Algo::Modelisation::Polyhedron<PFP>::createTetra(myMap);
Dart d2 = d1;
// Dart d1 = Algo::Modelisation::Polyhedron<PFP>::createTetra(myMap);
position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position");
position[d2] = PFP::VEC3(1, 0, 0);
d2 = PHI1(d2);
position[d2] = PFP::VEC3(-1, 0, 0);
d2 = PHI1(d2);
position[d2] = PFP::VEC3(0, 2, 0);
d2 = PHI<211>(d2);
position[d2] = PFP::VEC3(0, 1, 2);
Algo::Modelisation::Polyhedron<PFP> prim1(myMap, position);
prim1.cylinder_topo(256,256, true, true); // topo of sphere is a closed cylinder
prim1.embedSphere(2.0f);
// Dart d2 = d1;
// position[d2] = PFP::VEC3(1, 0, 0);
// d2 = PHI1(d2);
// position[d2] = PFP::VEC3(-1, 0, 0);
// d2 = PHI1(d2);
// position[d2] = PFP::VEC3(0, 2, 0);
// d2 = PHI<211>(d2);
// position[d2] = PFP::VEC3(0, 1, 2);
Algo::Modelisation::Polyhedron<PFP> prim2(myMap, position);
prim2.cylinder_topo(256,256, true, true); // topo of sphere is a closed cylinder
prim2.embedSphere(2.0f);
Geom::Matrix44f trf;
trf.identity();
Geom::translate<float>(5.0f,0.0,0.0,trf);
prim2.transform(trf);
xd1 = prim2.getDart();
// xd1 = Algo::Modelisation::Polyhedron<PFP>::createTetra(myMap);
// Dart xd2 = xd1;
//
// position[xd2] = PFP::VEC3(5, 0, 0);
// xd2 = PHI1(xd2);
// position[xd2] = PFP::VEC3(3, 0, 0);
// xd2 = PHI1(xd2);
// position[xd2] = PFP::VEC3(4, 2, 0);
// xd2 = PHI<211>(xd2);
// position[xd2] = PFP::VEC3(4, 1, 2);
// bounding box of scene
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
......
......@@ -26,256 +26,298 @@
#include "tuto5.h"
#include <iostream>
#include "Algo/Modelisation/primitives3d.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Modelisation/subdivision.h"
#include "Algo/Render/GL2/topo3Render.h"
#include "Algo/Render/SVG/mapSVGRender.h"
#include "Algo/Import/import.h"
PFP::MAP myMap;
PFP::TVEC3 position ;
Dart dglobal;
void MyQT::balls_onoff(bool x)
{
render_balls = !render_balls;
updateGL();
CGoGNerr << " balls_onoff "<< CGoGNendl;
}
void MyQT::vectors_onoff(bool x)
void MyQT::volumes_onoff(bool x)
{
render_vectors = !render_vectors;
render_volumes = !render_volumes;
updateGL();
CGoGNerr << " vectors_onoff "<< CGoGNflush;
}
void MyQT::text_onoff(bool x)
void MyQT::edges_onoff(bool x)
{
render_text = !render_text;
render_edges = !render_edges;
updateGL();
CGoGNerr << " text_onoff " << CGoGNflush;
}
void MyQT::topo_onoff(bool x)
{
render_topo = !render_topo;
if (render_topo)
{
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_topo_render->updateData<PFP>(myMap, position, 0.8f, 0.8f, m_explode_factor, nb);
}
updateGL();
CGoGNerr << " topo_onoff " << CGoGNflush;
}
void MyQT::slider_balls(int x)
void MyQT::clipping_onoff(bool x)
{
m_sprite->setSize(0.05f*x);
clip_volume = !clip_volume;
if (clip_volume)
{
Geom::Vec3f pos = m_PlanePick->getPosition();
float pipo;
Geom::Vec3f normal = m_PlanePick->getAxisScale(2, pipo); // 2 = Z axis = plane normal
float d = -(pos*normal);
m_explode_render->setClippingPlane(Geom::Vec4f(normal[0],normal[1],normal[2],d));
m_topo_render->shader1()->setClipPlaneParamsAll(clip_id1, normal, pos);
m_topo_render->shader2()->setClipPlaneParamsAll(clip_id2, normal, pos);
}
else
{
m_explode_render->setNoClippingPlane();
m_topo_render->shader1()->setClipPlaneParamsAll(clip_id1, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f));
m_topo_render->shader2()->setClipPlaneParamsAll(clip_id2, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f));
m_topo_render->shader1()->setClipColorAttenuationFactorRelative(0.0f,0.0f);
m_topo_render->shader2()->setClipColorAttenuationFactorRelative(0.0f,0.0f);
}
updateGL();
}
void MyQT::slider_vectors(int x)
void MyQT::hide_onoff(bool x)
{
m_lines->setScale(0.02*x);
hide_clipping = !hide_clipping;
updateGL();
}
void MyQT::slider_text(int x)
void MyQT::slider_explode(int x)
{
m_strings->setScale(0.02f*x);
m_explode_factor = 0.01f*x;
m_explode_render->setExplodeVolumes(m_explode_factor);
updateGL();
}
void MyQT::animate()
void MyQT::slider_pressed()
{
// transfoMatrix() = glm::rotate(transfoMatrix(), 0.5f, glm::vec3(0.5773f,0.5773f,0.5773f));
transfoRotate( 0.5f, 0.5773f,0.5773f,0.5773f);
updateGLMatrices();
render_topoTemp = render_topo;
render_topo = false;
updateGL();
}
void MyQT::storeVerticesInfo()
void MyQT::slider_released()
{
CellMarker mv(myMap,VERTEX);
for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d))
render_topo = render_topoTemp;
if (render_topo)
{
if (!mv.isMarked(d))
{
mv.mark(d);
std::stringstream ss;
ss << d << " : "<< position[d];
m_strings->addString(ss.str(),position[d]);
}
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_topo_render->updateData<PFP>(myMap, position, 0.8f, 0.8f, m_explode_factor, nb);
}
updateGL();
}
void MyQT::cb_initGL()
{
// choose to use GL version 2
Utils::GLSLShader::setCurrentOGLVersion(2);
// create the render
m_render = new Algo::Render::GL2::MapRender();
m_render_topo = new Algo::Render::GL2::Topo3Render();
// create VBO for position
m_positionVBO = new Utils::VBO();
m_positionVBO->updateData(position);
// create the renders
m_topo_render = new Algo::Render::GL2::Topo3Render();
m_explode_render = new Algo::Render::GL2::ExplodeVolumeRender();
// using simple shader with color
m_shader = new Utils::ShaderSimpleColor();
m_shader->setAttributePosition(m_positionVBO);
m_shader->setColor(Geom::Vec4f(0.,1.,0.,0.));
m_sprite = new Utils::PointSprite();
m_sprite->setAttributePosition(m_positionVBO);
m_strings = new Utils::Strings3D(true, Geom::Vec3f(0.1f,0.0f,0.3f));
storeVerticesInfo();
m_strings->sendToVBO();
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_topo_render->updateData<PFP>(myMap, position, 0.8f, 0.8f, 0.8f, nb);
m_explode_render->updateData<PFP>(myMap,position);
m_explode_render->setExplodeVolumes(0.8f);
m_explode_render->setColorLine(Geom::Vec4f(0.3f,0.3f,0.3f,1.0f));
// copy de contenu de VBO a la creation
m_dataVBO = new Utils::VBO(*m_positionVBO);
registerShader(m_explode_render->shaderFaces());
registerShader(m_explode_render->shaderLines());
m_lines = new Utils::ShaderVectorPerVertex();
m_lines->setAttributePosition(m_positionVBO);
m_lines->setAttributeVector(m_dataVBO);
m_lines->setScale(0.2f);
m_lines->setColor(Geom::Vec4f(0.0f, 1.0f, 0.2f, 0.0f));
m_PlanePick = new Utils::Pickable(Utils::Pickable::GRID,1);
m_frame = new Utils::FrameManipulator();
m_frame->setSize(m_WidthObj/2.0f);
// accede au buffer du VBO pour modification
PFP::VEC3* data = static_cast<PFP::VEC3*>(m_dataVBO->lockPtr());
for (unsigned int i=0; i< m_dataVBO->nbElts(); ++i)
{
data[i].normalize();
}
m_dataVBO->releasePtr();
registerShader(m_shader);
registerShader(m_strings);
registerShader(m_sprite);
registerShader(m_lines);
m_topo_render->shader1()->insertClippingCode();
m_topo_render->shader2()->insertClippingCode();
SelectorTrue allDarts;
clip_id1 = m_topo_render->shader1()->addClipPlane();
clip_id2 = m_topo_render->shader2()->addClipPlane();
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::POINTS);
m_topo_render->shader1()->setClipPlaneParamsAll(clip_id1, Geom::Vec3f(0,0,1), m_PosObj);
m_topo_render->shader2()->setClipPlaneParamsAll(clip_id2, Geom::Vec3f(0,0,1), m_PosObj);
m_explode_render->setClippingPlane(Geom::Vec4f(0,0,1,m_PosObj*Geom::Vec3f(0,0,-1)));
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f, 0.9f, nb);
}
// timer example for animation
m_timer = new QTimer( this );
connect( m_timer, SIGNAL(timeout()), SLOT(animate()) );
}
void MyQT::cb_redraw()
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
m_render->draw(m_shader, Algo::Render::GL2::POINTS);
glLineWidth(2.0f);
m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.));
m_render->draw(m_shader, Algo::Render::GL2::LINES);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
if (render_topo)
m_render_topo->drawTopo();
m_topo_render->drawTopo();
/* Dart d = myMap.phi2(myMap.begin());
m_render_topo->overdrawDart(d, 5, 1.0f, 0.0f, 1.0f);
d = myMap.phi1(myMap.begin());
m_render_topo->overdrawDart(d, 5, 1.0f, 0.0f, 1.0f);
*/
m_render_topo->overdrawDart(m_selected, 5, 1.0f, 0.0f, 1.0f);
if (render_edges)
{
glLineWidth(1.0f);
m_explode_render->drawEdges();
}
glDisable(GL_POLYGON_OFFSET_FILL);
if (render_text)
m_strings->drawAll(Geom::Vec3f(0.0f, 1.0f, 1.0f));
if (render_balls)
if (render_volumes)
{
m_sprite->predraw(Geom::Vec3f(1.0f, 0.0f ,0.0f));
m_render->draw(m_sprite, Algo::Render::GL2::POINTS);
m_sprite->postdraw();
m_explode_render->drawFaces();
}
if (render_vectors)
if (clip_volume && !hide_clipping)
{
glLineWidth(1.0f);
m_render->draw(m_lines, Algo::Render::GL2::POINTS);
m_frame->draw();
m_PlanePick->draw();
}
}
void MyQT::cb_mousePress(int button, int x, int y)
void MyQT::cb_mousePress(int button, int x, int y)
{
if (Shift())
if (!Shift())
return;
if (hide_clipping || !clip_volume)
return;
m_begX = x;
m_begY = y;
// get ray of selection
Geom::Vec3f rayA,rayB;
float dist = getOrthoScreenRay(x,y,rayA,rayB);
Geom::Vec3f AB = rayB-rayA;
unsigned int fr_picked =0;
// picking the frame -> axis
fr_picked = m_frame->pick(rayA,AB,dist);
if (fr_picked != 0)
{
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
Dart d = m_render_topo->picking<PFP>(myMap, x,y, nb);
if (d != Dart::nil())
{
CGoGNout << "Dart "<< d << " clicked" << CGoGNendl;
m_selected = d;
}
else
{
statusMsg("");
}
m_pickedAxis=fr_picked;
std::cout << "PICKED:"<< m_pickedAxis << std::endl;
m_frame->highlight(m_pickedAxis);
m_frame->storeProjection(m_pickedAxis);
updateGL();
}
}
void MyQT::cb_keyPress(int code)
void MyQT::cb_mouseRelease(int button, int x, int y)
{
if (code == 's')
if (hide_clipping || !clip_volume)
return;
m_pickedAxis=0;
m_frame->highlight(m_pickedAxis);
updateGL();
}
void MyQT::cb_mouseMove(int buttons, int x, int y)
{
if (!Shift())
return;
if (hide_clipping || !clip_volume)
return;
// rotation selected ?
if (Utils::FrameManipulator::rotationAxis(m_pickedAxis))
{
std::string filename = selectFileSave("Export SVG file ");
CGoGNout << "Exporting "<<filename<<CGoGNendl;
Algo::Render::SVG::SVGOut svg(filename,modelViewMatrix(),projectionMatrix());
// svg.renderLinesToSVG<PFP>(myMap,position);
svg.setColor(Geom::Vec3f(1.,0.,0.));
svg.renderFacesToSVG<PFP>(myMap,position,0.8f);
//svg destruction close the file
if (buttons&1)
{
float angle = m_frame->angleFromMouse(x,y,x-m_begX, y-m_begY);
m_frame->rotate(m_pickedAxis, angle);
}
else if (buttons&2)
m_frame->rotateInScreen(x-m_begX, y-m_begY);
m_PlanePick->transfo() = m_frame->transfo();