59 #include <ACG/Scenegraph/DrawModes.hh>
63 #include <ACG/Scenegraph/ManipulatorNode.hh>
64 #include <ACG/Scenegraph/BoundingBoxNode.hh>
65 #include <ACG/QtScenegraph/QtTranslationManipulatorNode.hh>
72 template <
class MeshT >
101 template <
class MeshT >
115 setDataType(_typeId);
122 template <
class MeshT >
133 if ( mesh_ != NULL) {
137 std::cerr <<
"Destructor error : Mesh already deleted" << std::endl;
140 if ( triangle_bsp_ != 0 )
141 delete triangle_bsp_;
157 template <
class MeshT >
160 if ( mesh_ != NULL) {
164 std::cerr <<
"Cleanup error : Triangle Mesh already deleted" << std::endl;
167 if ( triangle_bsp_ != 0 )
168 delete triangle_bsp_;
189 template <
class MeshT >
195 mesh_ =
new MeshT(*_mesh);
198 mesh_->request_vertex_normals();
199 mesh_->request_face_normals();
200 mesh_->request_vertex_status();
201 mesh_->request_halfedge_status();
202 mesh_->request_face_status();
203 mesh_->request_edge_status();
204 mesh_->request_vertex_colors();
205 mesh_->request_face_colors();
208 if ( OpenFlipper::Options::nogui() )
212 if ( manipulatorNode() == NULL)
213 std::cerr <<
"Error when creating Mesh Object! manipulatorNode is NULL!" << std::endl;
222 QString shaderDir = OpenFlipper::Options::shaderDirStr() + OpenFlipper::Options::dirSeparator();
224 std::string shaderDirectory = std::string( shaderDir.toUtf8() );
225 shaderNode_->setShaderDir( shaderDirectory );
227 if(!OpenFlipper::Options::coreProfile())
229 if ( QFile( shaderDir +
"Phong/Vertex.glsl").exists() && QFile( shaderDir +
"Phong/Fragment.glsl" ).exists() )
232 std::cerr <<
"Shader Files for Phong not found!" << std::endl;
237 statusNode_->set_point_size(4.0);
238 statusNode_->set_color(
ACG::Vec4f(1.0f,0.0f,0.0f,1.0f));
239 statusNode_->set_base_color(
ACG::Vec4f(1.0f,0.0f,0.0f,1.0f));
246 areaNode_->set_round_points(
true);
247 areaNode_->enable_alpha_test(0.5);
248 areaNode_->set_point_size(7.0);
256 handleNode_->set_round_points(
true);
257 handleNode_->enable_alpha_test(0.5);
258 handleNode_->set_line_width(2.0);
259 handleNode_->set_point_size(7.0);
260 handleNode_->set_color(
ACG::Vec4f(0.2f, 1.0f, 0.2f, 1.0f));
267 featureNode_->set_round_points(
true);
268 featureNode_->enable_alpha_test(0.5);
269 featureNode_->set_line_width(2.0);
270 featureNode_->set_point_size(7.0);
271 featureNode_->set_color(
ACG::Vec4f(1.0f, 0.2f, 1.0f, 1.0f));
272 featureNode_->set_base_color(
ACG::Vec4f(1.0f, 0.2f, 1.0f, 1.0f));
279 statusNode_->
setDrawMesh(meshNode_->getDrawMesh());
280 featureNode_->setDrawMesh(meshNode_->getDrawMesh());
281 areaNode_->setDrawMesh(meshNode_->getDrawMesh());
282 handleNode_->setDrawMesh(meshNode_->getDrawMesh());
293 statusNode_->set_parent(statusView_);
294 areaNode_->set_parent(statusView_);
295 handleNode_->set_parent(statusView_);
296 featureNode_->set_parent(statusView_);
309 template <
class MeshT >
314 if ( OpenFlipper::Options::nogui() )
317 std::string nodename = std::string(
"StatusNode for mesh " + _name.toUtf8() );
318 statusNode_->name( nodename );
320 nodename = std::string(
"AreaNode for mesh " + _name.toUtf8() );
321 areaNode_->name( nodename );
323 nodename = std::string(
"HandleNode for mesh " + _name.toUtf8() );
324 handleNode_->name( nodename );
326 nodename = std::string(
"FeatureNode for mesh " + _name.toUtf8() );
327 featureNode_->name( nodename );
329 nodename = std::string(
"TextureNode for mesh "+ _name.toUtf8() );
330 textureNode_->name( nodename );
332 nodename = std::string(
"ShaderNode for mesh "+ _name.toUtf8() );
333 shaderNode_->name( nodename );
335 nodename = std::string(
"MeshNode for mesh " + _name.toUtf8() );
336 meshNode_->name( nodename );
338 nodename = std::string(
"StatusViewNode for mesh " + _name.toUtf8() );
339 statusView_->name( nodename );
349 template <
class MeshT >
357 template <
class MeshT >
366 template <
class MeshT >
370 if ( OpenFlipper::Options::nogui() )
381 updateModelingRegions();
392 updateModelingRegions();
404 template <
class MeshT >
408 statusNode_->updateSelection();
413 template <
class MeshT >
417 meshNode_->update_geometry();
422 statusNode_->updateGeometry();
423 featureNode_->updateGeometry();
424 areaNode_->updateGeometry();
425 handleNode_->updateGeometry();
429 invalidateTriangleBsp();
433 template <
class MeshT >
436 meshNode_->update_color();
440 template <
class MeshT >
443 meshNode_->update_topology();
444 statusNode_->updateTopology();
445 featureNode_->updateTopology();
446 areaNode_->updateTopology();
447 handleNode_->updateTopology();
449 invalidateTriangleBsp();
453 template <
class MeshT >
455 if ( areaNode_ && handleNode_ ) {
456 areaNode_->updateSelection();
457 handleNode_->updateSelection();
462 template <
class MeshT >
465 featureNode_->updateSelection();
469 template <
class MeshT >
471 meshNode_->update_textures();
478 template <
class MeshT >
483 statusNode_->set_color(_color);
484 statusNode_->set_base_color(_color);
488 template <
class MeshT >
492 return statusNode_->base_color();
497 template <
class MeshT >
502 areaNode_->set_color(_color);
503 areaNode_->set_base_color(_color);
506 template <
class MeshT >
510 return areaNode_->base_color();
515 template <
class MeshT >
520 featureNode_->set_color(_color);
521 featureNode_->set_base_color(_color);
524 template <
class MeshT >
528 return featureNode_->base_color();
533 template <
class MeshT >
538 handleNode_->set_color(_color);
539 handleNode_->set_base_color(_color);
542 template <
class MeshT >
546 return handleNode_->base_color();
555 template <
class MeshT >
563 template <
class MeshT >
570 template <
class MeshT >
581 template <
class MeshT >
590 template <
class MeshT >
597 template <
class MeshT >
607 areaNode_->set_status( status );
610 if ( _bit & HANDLEAREA )
611 handleNode_->set_status( status );
615 template <
class MeshT >
620 template <
class MeshT >
627 if ( _bit & HANDLEAREA )
636 template <
class MeshT >
643 template <
class MeshT >
647 _bbMin = mesh_->point(mesh_->vertex_handle(0));
648 _bbMax = mesh_->point(mesh_->vertex_handle(0));
649 for (
auto v_it : mesh_->vertices()) {
656 std::cerr <<
"Error: No Mesh found" << std::endl;
669 template <
class MeshT >
672 setFromFileName(_filename);
677 std::string filename = std::string( _filename.toUtf8() );
683 if ( dataType() ==
typeId(
"TriangleMesh") )
684 std::cerr <<
"Main Application : Read error for Triangle Mesh at "<< filename << std::endl;
685 if ( dataType() ==
typeId(
"PolyMesh") )
686 std::cerr <<
"Main Application : Read error for Poly Mesh\n";
708 template <
class MeshT >
712 output +=
"========================================================================\n";
715 if ( dataType(
typeId(
"TriangleMesh") ) )
716 output +=
"Object Contains Triangle Mesh : ";
718 if ( dataType(
typeId(
"PolyMesh") ) )
719 output +=
"Object Contains Poly Mesh : ";
721 output += QString::number( mesh()->n_vertices() ) +
" vertices, ";
722 output += QString::number( mesh()->n_edges() ) +=
" edges ";
723 output += QString::number( mesh()->n_faces() ) +=
" faces.\n";
725 output +=
"========================================================================\n";
739 template <
class MeshT >
741 return ( _node_idx == meshNode_->id() );
745 template <
class MeshT >
747 if ( OpenFlipper::Options::nogui())
750 meshNode_->enablePicking( _enable );
751 areaNode_->enablePicking( _enable );
752 handleNode_->enablePicking( _enable );
753 featureNode_->enablePicking( _enable );
754 textureNode_->enablePicking( _enable );
755 shaderNode_->enablePicking( _enable );
758 template <
class MeshT >
760 return meshNode_->pickingEnabled();
767 template <
class MeshT >
771 if ( ! dataType(
typeId(
"TriangleMesh") ) ) {
772 std::cerr <<
"Bsps are only supported for triangle meshes." << std::endl;
777 if ( triangle_bsp_ == 0 )
783 triangle_bsp_->reserve(mesh()->n_faces());
785 typename MeshT::FIter f_it = mesh()->faces_begin();
786 typename MeshT::FIter f_end = mesh()->faces_end();
788 for (; f_it!=f_end; ++f_it)
789 triangle_bsp_->push_back(*f_it);
791 triangle_bsp_->build(10, 100);
795 return triangle_bsp_;
798 template <
class MeshT >
801 if ( triangle_bsp_ != 0 )
803 delete triangle_bsp_;
807 return requestTriangleBsp();
810 template <
class MeshT >
813 if ( triangle_bsp_ != 0 )
815 delete triangle_bsp_;
821 template <
class MeshT >
824 return triangle_bsp_ != 0;
830 template <
class MeshT >
833 return boundingBoxNode();
DLLEXPORT DataType typeId(QString _name)
Given a dataType Identifier string this function will return the id of the datatype.
@ HideNode
Hide this node, but draw children.
@ Active
Draw node & children.
void set_status(StatusMode _s)
Set the status of this node.
void setDrawMesh(DrawMeshT< Mesh > *_drawmesh)
Set drawmesh.
virtual void setName(QString _name) override
path to the file from which the object is loaded ( defaults to "." )
virtual void cleanup() override
virtual QString getObjectinfo()
Get all Info for the Object as a string.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
bool areaVisible(StatusBits _bit)
Return if the selected areas are currently visible.
QString getObjectinfo()
Get all Info for the Object as a string.
void updateTexture()
Update Texture of all data structures.
BaseNode * primaryNode()
Status Node for a mesh, visualizing the selection state of a mesh.
ACG::Vec4f selectionColor() const
get color for selection. returns -1 vector, if handle node does not exists
MeshT * mesh_
pointer to the mesh
bool featuresVisible()
return if the feature Node of the object is currently visible
void invalidateTriangleBsp()
void hideFeatures(bool _hide)
Hide or show the feature Node of the object.
bool hasBsp() const
check if a BSP has been computed and is valid
OMTriangleBSP * requestTriangleBsp()
virtual ~MeshObject()
destructor
void updateSelection()
Call this function to update the modeling regions.
OMTriangleBSP * resetTriangleBsp()
bool selectionVisible()
return if the selections are currently visible
void setHandleColor(const ACG::Vec4f &_color)
set color for handles
bool pickingEnabled()
Check if picking is enabled for this Node.
void setAreaColor(const ACG::Vec4f &_color)
set color for areas
void updateGeometry()
Update Geometry of all data structures.
ACG::SceneGraph::MeshNodeT< MeshT > * meshNode()
Get the Scenegraph Mesh Node.
void boundingBox(ACG::Vec3d &_bbMin, typename ACG::Vec3d &_bbMax)
Get the BoundingBox of this object.
MeshT * mesh()
return a pointer to the mesh
ACG::Vec4f areaColor() const
get color for areas. returns -1 vector, if handle node does not exists
ACG::Vec4f featureColor() const
get color for features. returns -1 vector, if handle node does not exists
MeshObject(const MeshObject &_object)
copy constructor
void setFeatureColor(const ACG::Vec4f &_color)
set color for features
void enablePicking(bool _enable)
Enable or disable picking for this Node.
void hideSelection(bool _hide)
Hide or show the selection Node of the object.
virtual void cleanup()
Reset current object, including all related nodes.
void updateColor()
Update Colors of all data structures.
ACG::SceneGraph::EnvMapNode * textureNode()
Get the TextureNode of the current mesh.
ACG::Vec4f handleColor() const
get color for handles. returns -1 vector, if handle node does not exists
void setName(QString _name)
Set the name of the Object.
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
void hideArea(StatusBits _bit, bool _hide)
Hide or show the area Nodes of the object.
void updateFeatures()
Update Feature Visualization Node.
void updateModelingRegions()
Call this function to update the modeling regions.
ACG::SceneGraph::ShaderNode * shaderNode()
Return pointer to the shader node.
bool loadMesh(QString _filename)
Load a mesh from the given file.
bool picked(uint _node_idx)
detect if the node has been picked
void updateTopology()
Update Topology of all data structures.
virtual void init(MeshT *_mesh=0)
Initialise current object, including all related nodes.
void setSelectionColor(const ACG::Vec4f &_color)
set color for selection
void update_normals()
Compute normals for all primitives.
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
const UpdateType UPDATE_TEXTURE(UpdateTypeSet(2048))
Textures have changed.
const UpdateType UPDATE_TOPOLOGY(UpdateTypeSet(8))
Topology updated.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(4))
Geometry updated.
const UpdateType UPDATE_COLOR(UpdateTypeSet(1024))
Colors have changed.
const UpdateType UPDATE_SELECTION(UpdateTypeSet(16))
Selection updated.
DrawMode SOLID_PHONG_SHADED
draw phong shaded faces
DrawMode NONE
not a valid draw mode
VectorT< float, 4 > Vec4f
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
void setMainGLContext()
Set current GL Context to main context.