diff --git a/src/DisplayGUI/DisplayGUI.cxx b/src/DisplayGUI/DisplayGUI.cxx index 7ce28c184..6e4b90646 100644 --- a/src/DisplayGUI/DisplayGUI.cxx +++ b/src/DisplayGUI/DisplayGUI.cxx @@ -327,7 +327,13 @@ void DisplayGUI::Erase() listIO.Append( anIObject ); } } - GEOM_Displayer(anActiveStudy).Erase( listIO, true ); + + SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow(); + bool aIsForced = true; + if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type()) + aIsForced = false; + + GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced); getGeometryGUI()->getApp()->selectionMgr()->clearSelected(); } diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index ee421a5d6..1aa62405a 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -1125,7 +1125,7 @@ void GeometryGUI::initialize( CAM_Application* app ) mgr->insert( action( 8033 ), -1, -1 ); // transparency mgr->setRule( action( 8033 ), clientOCCorVTK_AndSomeVisible, true ); mgr->insert( action( 8034 ), -1, -1 ); // isos - mgr->setRule( action( 8034 ), "client='OCCViewer' and selcount>0 and isVisible", true ); + mgr->setRule( action( 8034 ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", true ); mgr->insert( separator(), -1, -1 ); // ----------- @@ -1419,7 +1419,7 @@ bool GeometryGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QStr } else { ////// VTK viewer only - popup->removeItem( 8034 ); // "Isos" + //popup->removeItem( 8034 ); // "Isos" SVTK_Prs* vtkPrs = dynamic_cast( prs ); if ( vtkPrs && !vtkPrs->IsNull() ) { vtkActorCollection* actorList = vtkPrs->GetObjects(); @@ -1542,7 +1542,7 @@ bool GeometryGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QStr popup->removeItem( QAD_Display_Popup_ID ); if ( !needErase ) popup->removeItem( QAD_Erase_Popup_ID ); - if ( !isOCCViewer ) + if ( !isOCCViewer && !isVTKViewer) popup->removeItem( 8034 ); // "Isos" } } @@ -1587,7 +1587,7 @@ void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win ) return; const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() ); -// const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() ); + const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() ); // disable non-OCC viewframe menu commands // action( 404 )->setEnabled( ViewOCC ); // SKETCHER @@ -1598,6 +1598,7 @@ void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win ) action( 608 )->setEnabled( ViewOCC ); // AddPointOnEdge // action( 609 )->setEnabled( ViewOCC ); // Free boundaries action( 413 )->setEnabled( ViewOCC ); // Isos Settings + action( 413 )->setEnabled( ViewVTK ); // Isos Settings action( 800 )->setEnabled( ViewOCC ); // Create Group action( 801 )->setEnabled( ViewOCC ); // Edit Group @@ -1674,14 +1675,9 @@ void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm ) QString GeometryGUI::engineIOR() const { - QString anIOR = QString::null; if ( !CORBA::is_nil( GetGeomGen() ) ) - { - CORBA::String_var objStr = getApp()->orb()->object_to_string( GetGeomGen() ); - anIOR = QString( objStr.in() ); -// free( objStr ); ASV : 26.07.06 : commented out because it raises exception and blocks application - } - return anIOR; + return QString( getApp()->orb()->object_to_string( GetGeomGen() ) ); + return QString( "" ); } LightApp_Selection* GeometryGUI::createSelection() const diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx index 2becab38d..4587ec672 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx @@ -245,7 +245,7 @@ void GEOMToolsGUI::OnColor() return; SVTK_View* aView = vtkVW->getView(); QColor initcolor = aView->GetColor( selected.First() ); - QColor c = QColorDialog::getColor( QColor(), app->desktop() ); + QColor c = QColorDialog::getColor( initcolor, app->desktop() ); if ( c.isValid() ) { SUIT_OverrideCursor(); for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) { @@ -304,45 +304,107 @@ void GEOMToolsGUI::OnTransparency() void GEOMToolsGUI::OnNbIsos() { SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); + bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() ); + const bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() ); - if ( !isOCC ) - return; + // if is OCCViewer + if(isOCC){ - OCCViewer_Viewer* vm = dynamic_cast( window->getViewManager()->getViewModel() ); - Handle (AIS_InteractiveContext) ic = vm->getAISContext(); + OCCViewer_Viewer* vm = dynamic_cast( window->getViewManager()->getViewModel() ); + Handle (AIS_InteractiveContext) ic = vm->getAISContext(); - ic->InitCurrent(); - if ( ic->MoreCurrent() ) { - Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current()); - Handle(AIS_Drawer) CurDrawer = CurObject->Attributes(); - - int UIso = CurDrawer->UIsoAspect()->Number(); - int VIso = CurDrawer->VIsoAspect()->Number(); - - GEOMToolsGUI_NbIsosDlg * NbIsosDlg = - new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() ); - - NbIsosDlg->setU( UIso ); - NbIsosDlg->setV( VIso ); - - if ( NbIsosDlg->exec() ) { - SUIT_OverrideCursor(); - for(; ic->MoreCurrent(); ic->NextCurrent()) { - CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current()); - Handle(AIS_Drawer) CurDrawer = CurObject->Attributes(); - - int nbUIso = NbIsosDlg->getU(); - int nbVIso = NbIsosDlg->getV(); - - CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) ); - CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) ); - - ic->SetLocalAttributes(CurObject, CurDrawer); - ic->Redisplay(CurObject); + ic->InitCurrent(); + if ( ic->MoreCurrent() ) { + Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current()); + Handle(AIS_Drawer) CurDrawer = CurObject->Attributes(); + + int UIso = CurDrawer->UIsoAspect()->Number(); + int VIso = CurDrawer->VIsoAspect()->Number(); + + GEOMToolsGUI_NbIsosDlg * NbIsosDlg = + new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() ); + + NbIsosDlg->setU( UIso ); + NbIsosDlg->setV( VIso ); + + if ( NbIsosDlg->exec() ) { + SUIT_OverrideCursor(); + for(; ic->MoreCurrent(); ic->NextCurrent()) { + CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current()); + Handle(AIS_Drawer) CurDrawer = CurObject->Attributes(); + + int nbUIso = NbIsosDlg->getU(); + int nbVIso = NbIsosDlg->getV(); + + CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) ); + CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) ); + + ic->SetLocalAttributes(CurObject, CurDrawer); + ic->Redisplay(CurObject); + } } } - } + } else if(isVTK){ // if is VTKViewer + + // + // Warning. It's works incorrect. must be recheked. + // + SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); + if ( !app ) + return; + LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); + if ( !aSelMgr ) + return; + SALOME_ListIO selected; + aSelMgr->selectedObjects( selected ); + if ( selected.IsEmpty() ) + return; + + Handle(SALOME_InteractiveObject) FirstIOS = selected.First(); + if ( FirstIOS.IsNull() ) + return; + + SVTK_ViewWindow* vtkVW = dynamic_cast( window ); + if ( !vtkVW ) + return; + + SVTK_View* aView = vtkVW->getView(); + vtkActorCollection* aCollection = aView->getRenderer()->GetActors(); + + int UIso = 0; + int VIso = 0; + if(aCollection){ + aCollection->InitTraversal(); + } + + vtkActor *anAct = aCollection->GetNextActor(); + if(GEOM_Actor *anActor = dynamic_cast(anAct)){ + anActor->GetNbIsos(UIso,VIso); + } + + + GEOMToolsGUI_NbIsosDlg * NbIsosDlg = + new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() ); + + NbIsosDlg->setU( UIso ); + NbIsosDlg->setV( VIso ); + + if ( NbIsosDlg->exec() ) { + SUIT_OverrideCursor(); + + while(anAct = aCollection->GetNextActor()) { + if(GEOM_Actor *anActor = dynamic_cast(anAct)){ + // There are no casting to needed actor. + UIso = NbIsosDlg->getU(); + VIso = NbIsosDlg->getV(); + int aIsos[2]={UIso,VIso}; + anActor->SetNbIsos(aIsos); + } + } + } + } // end vtkviewer + } void GEOMToolsGUI::OnOpen() diff --git a/src/OBJECT/GEOM_Actor.cxx b/src/OBJECT/GEOM_Actor.cxx index e1ff41541..29eb27772 100644 --- a/src/OBJECT/GEOM_Actor.cxx +++ b/src/OBJECT/GEOM_Actor.cxx @@ -30,203 +30,495 @@ \class GEOM_Actor GEOM_Actor.h \brief This class allows to display an OpenCASCADE CAD model in a VTK viewer. */ +#include "GEOM_Actor.h" + +#include "GEOM_DeviceActor.h" +#include "GEOM_VertexSource.h" +#include "GEOM_EdgeSource.h" +#include "GEOM_WireframeFace.h" +#include "GEOM_ShadingFace.h" +#include "SVTK_Actor.h" -#include "GEOM_Actor.h" - -#include -#include -#include -#include - +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include #include #include #include - -#include -#include #include -// OpenCASCADE Includes -#include "GEOM_OCCReader.h" -#include +//vtkStandardNewMacro(GEOM_Actor); -using namespace std; +#ifndef MYDEBUG +//#define MYDEBUG +#endif -//------------------------------------------------------------- -// Main methods -//------------------------------------------------------------- +GEOM_Actor::GEOM_Actor(): + // myDisplayMode(eWireframe), + myIsSelected(false), + + myVertexActor(GEOM_DeviceActor::New(),true), + myVertexSource(GEOM_VertexSource::New(),true), + + myIsolatedEdgeActor(GEOM_DeviceActor::New(),true), + myIsolatedEdgeSource(GEOM_EdgeSource::New(),true), + + myOneFaceEdgeActor(GEOM_DeviceActor::New(),true), + myOneFaceEdgeSource(GEOM_EdgeSource::New(),true), + + mySharedEdgeActor(GEOM_DeviceActor::New(),true), + mySharedEdgeSource(GEOM_EdgeSource::New(),true), + + myWireframeFaceActor(GEOM_DeviceActor::New(),true), + myWireframeFaceSource(GEOM_WireframeFace::New(),true), + + myShadingFaceActor(GEOM_DeviceActor::New(),true), + myShadingFaceSource(GEOM_ShadingFace::New(),true), + + myHighlightActor(GEOM_DeviceActor::New(),true), + myAppendFilter(vtkAppendPolyData::New(),true), + myPolyDataMapper(vtkPolyDataMapper::New(),true), + myHighlightProp(vtkProperty::New()), + myPreHighlightProp(vtkProperty::New()), + myShadingFaceProp(vtkProperty::New()) + +{ +#ifdef MYDEBUG + cout <SetInput(myAppendFilter->GetOutput()); + vtkProperty* aProperty; + + myHighlightProp->SetAmbient(0.5); + myHighlightProp->SetDiffuse(0.3); + myHighlightProp->SetSpecular(0.2); + myHighlightProp->SetRepresentationToSurface(); + myHighlightProp->SetAmbientColor(1, 1, 1); + myHighlightProp->SetDiffuseColor(1, 1, 1); + myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5); + myHighlightActor->SetProperty(myHighlightProp.GetPointer()); + + this->myHighlightActor->SetInput(myAppendFilter->GetOutput(),false); + + myPreHighlightProp->SetColor(0,1,1); + myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2); + myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1); + myPreHighlightProp->SetRepresentationToWireframe(); + + myAppendFilter->AddInput(myVertexSource->GetOutput()); + myVertexActor->SetInput(myVertexSource->GetOutput(),false); + aProperty = myVertexActor->GetProperty(); + aProperty->SetRepresentation(VTK_POINTS); + aProperty->SetPointSize(3); + aProperty->SetColor(1, 1, 0); + + myAppendFilter->AddInput(myIsolatedEdgeSource->GetOutput()); + myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false); + aProperty = myIsolatedEdgeActor->GetProperty(); + aProperty->SetRepresentation(VTK_WIREFRAME); + aProperty->SetColor(1, 0, 0); + + myAppendFilter->AddInput(myOneFaceEdgeSource->GetOutput()); + myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false); + aProperty = myOneFaceEdgeActor->GetProperty(); + aProperty->SetRepresentation(VTK_WIREFRAME); + aProperty->SetColor(0, 1, 0); + + myAppendFilter->AddInput(mySharedEdgeSource->GetOutput()); + mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false); + aProperty = mySharedEdgeActor->GetProperty(); + aProperty->SetRepresentation(VTK_WIREFRAME); + aProperty->SetColor(1, 1, 0); + + myAppendFilter->AddInput(myWireframeFaceSource->GetOutput()); + myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false); + aProperty = myWireframeFaceActor->GetProperty(); + aProperty->SetRepresentation(VTK_WIREFRAME); + aProperty->SetColor(0.5, 0.5, 0.5); + + myShadingFaceActor->SetInput(myShadingFaceSource->GetOutput(),true); + + myShadingFaceProp->SetRepresentation(VTK_SURFACE); + myShadingFaceProp->SetInterpolationToGouraud(); + myShadingFaceProp->SetAmbient(1.0); + myShadingFaceProp->SetDiffuse(1.0); + myShadingFaceProp->SetSpecular(0.4); + myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451); + myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725); + myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843); + + myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer()); + + // Toggle display mode + setDisplayMode(0); // WIRE FRAME + +} + + +GEOM_Actor::~GEOM_Actor() +{ +#ifdef MYDEBUG + cout <Delete(); + myPreHighlightProp->Delete(); + myShadingFaceProp->Delete(); +} + +GEOM_Actor* +GEOM_Actor:: +New() +{ + GEOM_Actor* anObject = new GEOM_Actor(); + anObject->SetMapper(anObject->myPolyDataMapper.Get()); + return anObject; +} + + +void Write(vtkPolyData* theDataSet, const char* theFileName){ + vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New(); + cout<<"Write - "<GetNumberOfPoints()<<"; "<GetNumberOfCells()<SetInput(theDataSet); + aWriter->SetFileName(theFileName); + //aWriter->Write(); + aWriter->Delete(); +} + +void +GEOM_Actor:: +SetModified() +{ + this->myVertexSource->Modified(); + this->myIsolatedEdgeSource->Modified(); + this->myOneFaceEdgeSource->Modified(); + this->mySharedEdgeSource->Modified(); + this->myWireframeFaceSource->Modified(); + this->myShadingFaceSource->Modified(); +} + +void +GEOM_Actor:: +SetMapper(vtkMapper* theMapper) +{ + SALOME_Actor::SetMapper(theMapper); +} + +void +GEOM_Actor:: +AddToRender(vtkRenderer* theRenderer) { - // First try to create the object from the vtkObjectFactory - vtkObject* ret = vtkObjectFactory::CreateInstance("GEOM_Actor"); - if(ret) - { - return (GEOM_Actor*)ret; + //SALOME_Actor::AddToRender(theRenderer); + + theRenderer->AddActor(this); + + this->myHighlightActor->AddToRender(theRenderer); + + + myShadingFaceActor->AddToRender(theRenderer); + myWireframeFaceActor->AddToRender(theRenderer); + + mySharedEdgeActor->AddToRender(theRenderer); + myOneFaceEdgeActor->AddToRender(theRenderer); + myIsolatedEdgeActor->AddToRender(theRenderer); + + myVertexActor->AddToRender(theRenderer); +} + +void +GEOM_Actor:: +RemoveFromRender(vtkRenderer* theRenderer) +{ + //SALOME_Actor::RemoveFromRender(theRenderer); + + + theRenderer->RemoveActor(this); + + myHighlightActor->RemoveFromRender(theRenderer); + myShadingFaceActor->RemoveFromRender(theRenderer); + myWireframeFaceActor->RemoveFromRender(theRenderer); + + mySharedEdgeActor->RemoveFromRender(theRenderer); + myOneFaceEdgeActor->RemoveFromRender(theRenderer); + myIsolatedEdgeActor->RemoveFromRender(theRenderer); + + myVertexActor->RemoveFromRender(theRenderer); + + + SetSelected(false); + SetVisibility(false); +} + +void +GEOM_Actor:: +setDisplayMode(int theMode) +{ +#ifdef MYDEBUG + cout << "GEOM_Actor::SetDisplayMode = "<HighlightProperty = NULL; - this->myIsHighlighted = false; - - this->subshape = false; - this->myIsInfinite = false; -} - -GEOM_Actor::~GEOM_Actor() -{ - if (WireframeMapper != NULL) - WireframeMapper->Delete(); - if (ShadingMapper != NULL) - ShadingMapper->Delete(); - if (ShadingProperty != NULL) - ShadingProperty->Delete(); - if (WireframeProperty != NULL) - WireframeProperty->Delete(); - if (HighlightProperty != NULL) - HighlightProperty->Delete(); -} - - -void GEOM_Actor::ShallowCopy(vtkProp *prop) -{ - GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop); - if ( f != NULL ) - { - this->setInputShape(f->getTopo(),f->getDeflection(),f->getDisplayMode(),f->isVector()); - this->setName( f->getName() ); - if ( f->hasIO() ) - this->setIO( f->getIO() ); - this->ShadingMapper = NULL; - this->WireframeMapper = NULL; - } else { - this->myIO = NULL; - this->myName = ""; - this->ShadingMapper = NULL; - this->WireframeMapper = NULL; + switch(theShape.ShapeType()){ + case TopAbs_WIRE: { + TopExp_Explorer anEdgeExp(theShape,TopAbs_EDGE); + for(; anEdgeExp.More(); anEdgeExp.Next()){ + const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current()); + if(!BRep_Tool::Degenerated(anEdge)) + myIsolatedEdgeSource->AddEdge(anEdge); + } + break; } + case TopAbs_EDGE: { + const TopoDS_Edge& anEdge = TopoDS::Edge(theShape); + if(!BRep_Tool::Degenerated(anEdge)) + myIsolatedEdgeSource->AddEdge(anEdge); + break; + } + case TopAbs_VERTEX: { + break; + } + default: { + TopExp_Explorer aFaceExp(theShape,TopAbs_FACE); + for(; aFaceExp.More(); aFaceExp.Next()) { + const TopoDS_Face& aFace = TopoDS::Face(aFaceExp.Current()); + myWireframeFaceSource->AddFace(aFace); + myShadingFaceSource->AddFace(aFace); + TopExp_Explorer anEdgeExp(aFaceExp.Current(), TopAbs_EDGE); + for(; anEdgeExp.More(); anEdgeExp.Next()) { + const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current()); + if(!BRep_Tool::Degenerated(anEdge)){ + // compute the number of faces + int aNbOfFaces = theEdgeMap.FindFromKey(anEdge).Extent(); + switch(aNbOfFaces){ + case 0: // isolated edge + myIsolatedEdgeSource->AddEdge(anEdge); + break; + case 1: // edge in only one face + myOneFaceEdgeSource->AddEdge(anEdge); + break; + default: // edge shared by at least two faces + mySharedEdgeSource->AddEdge(anEdge); + } + } + } + } + } + } +} - // Now do superclass - this->SALOME_Actor::ShallowCopy(prop); -} - -//------------------------------------------------------------- -// Set parameters -//------------------------------------------------------------- - - -void GEOM_Actor::setDisplayMode(int thenewmode) { - myDisplayMode = thenewmode; - if ( thenewmode >=1 ) { - if ((myShape.ShapeType() == TopAbs_WIRE) || - (myShape.ShapeType() == TopAbs_EDGE) || - (myShape.ShapeType() == TopAbs_VERTEX)) { - if ( !subshape ) - CreateWireframeMapper(); - else - return; - } else - CreateShadingMapper(); - } else - CreateWireframeMapper(); -} - +// OLD METHODS void GEOM_Actor::setDeflection(double adef) { - deflection = adef; +#ifdef MYDEBUG + cout << "GEOM_Actor::setDeflection"<myHighlightActor->GetProperty()->DeepCopy(Prop); + } -//------------------------------------------------------------- -// Get parameters -//------------------------------------------------------------- - -const TopoDS_Shape& GEOM_Actor::getTopo() { - return myShape; +void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop) +{ +#ifdef MYDEBUG + cout << this << " GEOM_Actor::SetWireframeProperty"<SetProperty(Prop); } -double GEOM_Actor::getDeflection() { - return deflection; +void GEOM_Actor::SetShadingProperty(vtkProperty* Prop) +{ +#ifdef MYDEBUG + cout << "GEOM_Actor::SetShadingProperty"<DeepCopy(Prop); } -void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop) { - this->WireframeProperty = Prop; -} - -void GEOM_Actor::SetShadingProperty(vtkProperty* Prop) { - this->ShadingProperty = Prop; -} - - -//------------------------------------------------------------- -// Mapper creating function -//------------------------------------------------------------- -void GEOM_Actor::CreateMapper(int theMode) { - this->myIsInfinite = (bool)myShape.Infinite(); - if(myShape.ShapeType() == TopAbs_VERTEX) { - gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(myShape)); - this->SetPosition(aPnt.X(),aPnt.Y(),aPnt.Z()); - } - GEOM_OCCReader* aread = GEOM_OCCReader::New(); - aread->setTopo(myShape, myIsVector); - aread->setDisplayMode(theMode); - aread->GetOutput()->ReleaseDataFlagOn(); - - vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New(); - if (theMode == 0) { - aMapper->SetInput(aread->GetOutput()); - } else { - vtkPolyDataNormals *normals = vtkPolyDataNormals::New(); - normals->SetInput(aread->GetOutput()); - aMapper->SetInput(normals->GetOutput()); - } - aread->Delete(); - this->SetMapper(theMode == 0? WireframeMapper = aMapper : ShadingMapper = aMapper); -} - -void GEOM_Actor::CreateShadingMapper() { - CreateMapper(1); -} - - -void GEOM_Actor::CreateWireframeMapper() { - CreateMapper(0); -} - -//------------------------------------------------------------- -// Render function -//------------------------------------------------------------- void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *Mapper) { - /* render the property */ +#ifdef MYDEBUG + cout << "GEOM_Actor::Render"<Property) { // force creation of a property this->GetProperty(); @@ -238,17 +530,29 @@ void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *Mapper) this->Property->SetSpecularColor(0.99,0.98,0.83); } - if(!myIsHighlighted) { - if ( myIsPreselected ) - this->Property = PreviewProperty; - else if(myDisplayMode >= 1) { - // SHADING - this->Property = ShadingProperty; - } - else { - this->Property = WireframeProperty; - } + switch(myDisplayMode){ + case 0://wireframe + myPreHighlightProp->SetRepresentationToWireframe(); + myHighlightProp->SetRepresentationToWireframe(); + break; + case 1://shading + myPreHighlightProp->SetRepresentationToSurface(); + myHighlightProp->SetRepresentationToSurface(); + break; + } + if(!myIsSelected){ + if(myIsPreselected){ + this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer()); + myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer()); + } else { + this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer()); + myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer()); + } + } + else{ + this->myHighlightActor->SetProperty(myHighlightProp.GetPointer()); + myShadingFaceActor->SetProperty(myHighlightProp.GetPointer()); } this->Property->Render(this, ren); @@ -257,24 +561,6 @@ void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *Mapper) this->Device->SetBackfaceProperty(this->BackfaceProperty); } this->Device->SetProperty(this->Property); - // Store information on time it takes to render. - // We might want to estimate time from the number of polygons in mapper. - if(myDisplayMode >= 1) { - if((myShape.ShapeType() == TopAbs_WIRE) || - (myShape.ShapeType() == TopAbs_EDGE) || - (myShape.ShapeType() == TopAbs_VERTEX)) { - if ( !subshape ) { - if(WireframeMapper==NULL) CreateWireframeMapper(); - } else - return; - } - else { - if(ShadingMapper==NULL) CreateShadingMapper(); - } - } - else { - if(WireframeMapper==NULL) CreateWireframeMapper(); - } if(myShape.ShapeType() == TopAbs_VERTEX) { if(ren){ //The parameter determine size of vertex actor relate to diagonal of RendererWindow @@ -293,103 +579,199 @@ void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *Mapper) aMatrix->Delete(); } else this->Device->Render(ren, this->Mapper); - if(WireframeMapper!=NULL) this->EstimatedRenderTime = WireframeMapper->GetTimeToDraw(); - else if(ShadingMapper!=NULL) this->EstimatedRenderTime = ShadingMapper->GetTimeToDraw(); } -// SubShape +void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *) +{ +#ifdef MYDEBUG + cout << "GEOM_Actor::ReleaseGraphicsResources"<SetShape(f->getTopo(),f->GetDeflection(),f->GetIsRelative()); + } + + // Now do superclass + this->SALOME_Actor::ShallowCopy(prop); +} + +const TopoDS_Shape& GEOM_Actor::getTopo() { +#ifdef MYDEBUG + cout << "GEOM_Actor::getTopo"< -#include + +#include "GEOM_SmartPtr.h" +#include + +class GEOM_VertexSource; +typedef GEOM_SmartPtr PVertexSource; + +class GEOM_EdgeSource; +typedef GEOM_SmartPtr PEdgeSource; + +class GEOM_WireframeFace; +typedef GEOM_SmartPtr PWFaceSource; + +class GEOM_ShadingFace; +typedef GEOM_SmartPtr PSFaceSource; + +#include +class vtkRenderer; + +class vtkAppendPolyData; +typedef GEOM_SmartPtr PAppendFilter; -class vtkCamera; -class TopoDS_Shape; +class GEOM_OBJECT_EXPORT GEOM_Actor: public SALOME_Actor +{ +public: + vtkTypeMacro(GEOM_Actor,SALOME_Actor); + static GEOM_Actor* New(); + + void SetShape(const TopoDS_Shape& theShape, + float theDeflection, + bool theIsRelative); + + void SetDeflection(float theDeflection, bool theIsRelative); + float GetDeflection() const{ return myDeflection;} + bool GetIsRelative() const{ return myIsRelative;} + + void AddToRender(vtkRenderer* theRenderer); + void RemoveFromRender(vtkRenderer* theRenderer); -class GEOM_OBJECT_EXPORT GEOM_Actor : public SALOME_Actor { - public: - vtkTypeMacro(GEOM_Actor,SALOME_Actor); + enum EDisplayMode{ eWireframe, eShading}; + +/* void SetDisplayMode(EDisplayMode theMode); */ +/* EDisplayMode GetDisplayMode() const { return myDisplayMode;} */ + + void SetSelected(bool theIsSelected); + bool IsSelected() const { return myIsSelected;} - static GEOM_Actor* New(); + // OLD METHODS + // Properties + void SetHighlightProperty(vtkProperty* Prop); + void SetWireframeProperty(vtkProperty* Prop); + void SetShadingProperty(vtkProperty* Prop); + + void setDeflection(double adef); + virtual void setDisplayMode(int thenewmode); // Description: // This causes the actor to be rendered. It, in turn, will render the actor's // property and then mapper. virtual void Render(vtkRenderer *, vtkMapper *); - // Description: // Release any graphics resources that are being consumed by this actor. // The parameter window could be used to determine which graphic // resources to release. void ReleaseGraphicsResources(vtkWindow *); - const TopoDS_Shape& getTopo(); void setInputShape(const TopoDS_Shape& ashape, double adef1, int imode, bool isVector = false); - double getDeflection(); - void setDeflection(double adefl); - - double isVector() { return myIsVector; } + double isVector(); // SubShape void SubShapeOn(); void SubShapeOff(); - // Display Mode - virtual void setDisplayMode(int); - // Highlight virtual void highlight(bool theHighlight); virtual bool hasHighlight() { return true; } void ShallowCopy(vtkProp *prop); - // Properties - void SetHighlightProperty(vtkProperty* Prop); - void SetWireframeProperty(vtkProperty* Prop); - void SetShadingProperty(vtkProperty* Prop); - // Opacity void SetOpacity(vtkFloatingPointType opa); vtkFloatingPointType GetOpacity(); @@ -92,37 +123,97 @@ class GEOM_OBJECT_EXPORT GEOM_Actor : public SALOME_Actor { void SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b); void GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b); - virtual bool IsInfinite() {return myIsInfinite;} - protected: + virtual bool IsInfinite(); - GEOM_Actor(); - ~GEOM_Actor(); - GEOM_Actor(const GEOM_Actor&) {}; - void operator=(const GEOM_Actor&) {}; + // overloaded functions + //! To map current selection to VTK representation + virtual + void + Highlight(bool theHighlight); + + //---------------------------------------------------------------------------- + //! To process prehighlight (called from #SVTK_InteractorStyle) + virtual + bool + PreHighlight(vtkInteractorStyle* theInteractorStyle, + SVTK_SelectionEvent* theSelectionEvent, + bool theIsHighlight); + + //! To process highlight (called from #SVTK_InteractorStyle) + virtual + bool + Highlight(vtkInteractorStyle* theInteractorStyle, + SVTK_SelectionEvent* theSelectionEvent, + bool theIsHighlight); + + //! Visibility management + virtual + void + SetVisibility( int ); + + //! IsoLines management + // theNb[0] - number of U lines + // theNb[1] - number of V lines + virtual + void + SetNbIsos(const int theNb[2]); + + virtual + void + GetNbIsos(int &theNbU,int &theNbV); + +protected: + void SetShape(const TopoDS_Shape& theShape, + const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap); + + void SetModified(); - void CreateWireframeMapper(); - void CreateShadingMapper(); - void CreateMapper(int theMode); void GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result); - - - private: - - bool subshape; - bool myIsInfinite; - + + GEOM_Actor(); + ~GEOM_Actor(); + +private: TopoDS_Shape myShape; - double deflection; - bool myIsVector; - - vtkMapper* ShadingMapper; - vtkMapper* WireframeMapper; - - vtkProperty* ShadingProperty; - vtkProperty* WireframeProperty; - vtkProperty* HighlightProperty; -}; - - -#endif //GEOM_ACTOR_H - + int myNbIsos[2]; + + float myDeflection; + bool myIsRelative; + bool myIsForced; + + // EDisplayMode myDisplayMode; + bool myIsSelected; + + PDeviceActor myVertexActor; + PVertexSource myVertexSource; + + PDeviceActor myIsolatedEdgeActor; + PEdgeSource myIsolatedEdgeSource; + + PDeviceActor myOneFaceEdgeActor; + PEdgeSource myOneFaceEdgeSource; + + PDeviceActor mySharedEdgeActor; + PEdgeSource mySharedEdgeSource; + + PDeviceActor myWireframeFaceActor; + PWFaceSource myWireframeFaceSource; + + PDeviceActor myShadingFaceActor; + PSFaceSource myShadingFaceSource; + + PDeviceActor myHighlightActor; + vtkSmartPointer myHighlightProp; + vtkSmartPointer myPreHighlightProp; + vtkSmartPointer myShadingFaceProp; + + PAppendFilter myAppendFilter; + PPolyDataMapper myPolyDataMapper; + + virtual void SetMapper(vtkMapper*); + + GEOM_Actor(const GEOM_Actor&); + void operator=(const GEOM_Actor&); +}; + +#endif //GEOM_ACTOR_H diff --git a/src/OBJECT/GEOM_AssemblyBuilder.cxx b/src/OBJECT/GEOM_AssemblyBuilder.cxx index af6e55537..58c853cea 100644 --- a/src/OBJECT/GEOM_AssemblyBuilder.cxx +++ b/src/OBJECT/GEOM_AssemblyBuilder.cxx @@ -70,7 +70,7 @@ void GEOM_AssemblyBuilder::InitProperties(vtkProperty* IsoProp, vtkProperty* VertexProp, vtkProperty* IsoPVProp, vtkProperty* EdgePVProp, - vtkProperty* VertexPVProp) + vtkProperty* VertexPVProp) { // Shading like default OCC material FaceProp->SetRepresentationToSurface(); @@ -191,8 +191,28 @@ vtkActorCollection* GEOM_AssemblyBuilder::BuildActors(const TopoDS_Shape& myShap Standard_Boolean forced, Standard_Boolean isVector) { - vtkActorCollection* AISActors = vtkActorCollection::New(); + /* + vtkProperty* IsoProp = vtkProperty::New(); + vtkProperty* FaceProp = vtkProperty::New(); + vtkProperty* EdgeFProp = vtkProperty::New(); + vtkProperty* EdgeSProp = vtkProperty::New(); + vtkProperty* EdgeIProp = vtkProperty::New(); + vtkProperty* VertexProp = vtkProperty::New(); + vtkProperty* IsoPVProp = vtkProperty::New(); + vtkProperty* EdgePVProp = vtkProperty::New(); + vtkProperty* VertexPVProp = vtkProperty::New(); + InitProperties(IsoProp,FaceProp,EdgeFProp,EdgeSProp,EdgeIProp,VertexProp,IsoPVProp,EdgePVProp,VertexPVProp); + */ + vtkActorCollection* AISActors = vtkActorCollection::New(); + MeshShape(myShape,deflection,forced); + GEOM_Actor* aGeomActor = GEOM_Actor::New(); + aGeomActor->SetShape(myShape,(float)deflection,false); + AISActors->AddItem(aGeomActor); + + aGeomActor->Delete(); + + /* if(myShape.ShapeType() == TopAbs_COMPOUND) { TopoDS_Iterator anItr(myShape); for(; anItr.More(); anItr.Next()) { @@ -320,6 +340,8 @@ vtkActorCollection* GEOM_AssemblyBuilder::BuildActors(const TopoDS_Shape& myShap AISActors->AddItem(VertexActor); } + */ + return AISActors; @@ -338,8 +360,7 @@ vtkAssembly* GEOM_AssemblyBuilder::BuildAssembly(const TopoDS_Shape& myShape, // Create a new vtkAssembly vtkAssembly* myVTKShape = vtkAssembly::New(); - - + /* // Create graphics properties vtkProperty* IsoProp = vtkProperty::New(); @@ -418,6 +439,8 @@ vtkAssembly* GEOM_AssemblyBuilder::BuildAssembly(const TopoDS_Shape& myShape, } myVTKShape->AddPart(myFaceAssembly); } + + */ return myVTKShape; diff --git a/src/OBJECT/GEOM_DeviceActor.cxx b/src/OBJECT/GEOM_DeviceActor.cxx new file mode 100755 index 000000000..167010b91 --- /dev/null +++ b/src/OBJECT/GEOM_DeviceActor.cxx @@ -0,0 +1,83 @@ +#include "GEOM_DeviceActor.h" + +#include + +#include +#include +#include +#include +#include +#include + +#include + +vtkStandardNewMacro(GEOM_DeviceActor); + +GEOM_DeviceActor::GEOM_DeviceActor(): + myStripper(vtkStripper::New(),true), + myPolyDataMapper(vtkPolyDataMapper::New(),true), + myPolyDataNormals(vtkPolyDataNormals::New(),true), + myActor(vtkActor::New(),true) +{ + myStripper->SetInput(myPolyDataNormals->GetOutput()); + myPolyDataMapper->SetInput(myStripper->GetOutput()); + + myActor->SetMapper(myPolyDataMapper.Get()); + myActor->PickableOff(); +} + +GEOM_DeviceActor::~GEOM_DeviceActor() +{ +} + +void +GEOM_DeviceActor:: +SetInput(vtkPolyData* thePolyData, bool theUseStripper) +{ + if(theUseStripper) + myPolyDataNormals->SetInput(thePolyData); + else + myPolyDataMapper->SetInput(thePolyData); +} + +void +GEOM_DeviceActor:: +SetProperty(vtkProperty* theProperty) +{ + myActor->SetProperty(theProperty); +} + +vtkProperty* +GEOM_DeviceActor:: +GetProperty() +{ + return myActor->GetProperty(); +} + +void +GEOM_DeviceActor:: +SetVisibility(int theVisibility) +{ + myActor->SetVisibility(theVisibility); +} + +int +GEOM_DeviceActor:: +GetVisibility() +{ + return myActor->GetVisibility(); +} + +void +GEOM_DeviceActor:: +AddToRender(vtkRenderer* theRenderer) +{ + theRenderer->AddActor(myActor.GetPointer()); +} + +void +GEOM_DeviceActor:: +RemoveFromRender(vtkRenderer* theRenderer) +{ + theRenderer->RemoveActor(myActor.GetPointer()); +} \ No newline at end of file diff --git a/src/OBJECT/GEOM_DeviceActor.h b/src/OBJECT/GEOM_DeviceActor.h new file mode 100755 index 000000000..85809daf5 --- /dev/null +++ b/src/OBJECT/GEOM_DeviceActor.h @@ -0,0 +1,60 @@ +#ifndef GEOM_DEVICEACTOR_H +#define GEOM_DEVICEACTOR_H + +#include "GEOM_SmartPtr.h" + +class vtkPoints; +typedef GEOM_SmartPtr PPoints; + +class vtkPolyData; +typedef GEOM_SmartPtr PPolyData; + +class vtkStripper; +typedef GEOM_SmartPtr PStripper; + +class vtkPolyDataNormals; +typedef GEOM_SmartPtr PPolyDataNormals; + +class vtkActor; +typedef GEOM_SmartPtr PActor; + +class vtkProperty; +class vtkRenderer; + +#include + + +class VTK_EXPORT GEOM_DeviceActor: public vtkObject +{ +public: + vtkTypeMacro(GEOM_DeviceActor,vtkObject); + static GEOM_DeviceActor* New(); + + void SetProperty(vtkProperty* theProperty); + vtkProperty* GetProperty(); + + void SetVisibility(int theVisibility); + int GetVisibility(); + + void SetInput(vtkPolyData* thePolyData, bool theUseStripper); + + void AddToRender(vtkRenderer* theRenderer); + void RemoveFromRender(vtkRenderer* theRenderer); + +protected: + PPolyDataNormals myPolyDataNormals; + PPolyDataMapper myPolyDataMapper; + PStripper myStripper; + PActor myActor; + + GEOM_DeviceActor(); + ~GEOM_DeviceActor(); + +private: + // Not implememnted + GEOM_DeviceActor(const GEOM_DeviceActor&); + void operator=(const GEOM_DeviceActor&); +}; + + +#endif //GEOM_DEVICEACTOR_H diff --git a/src/OBJECT/GEOM_EdgeSource.cxx b/src/OBJECT/GEOM_EdgeSource.cxx new file mode 100755 index 000000000..8055fc24a --- /dev/null +++ b/src/OBJECT/GEOM_EdgeSource.cxx @@ -0,0 +1,130 @@ +#include "GEOM_EdgeSource.h" + +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +vtkStandardNewMacro(GEOM_EdgeSource); + +GEOM_EdgeSource::GEOM_EdgeSource() +{ +} + +GEOM_EdgeSource::~GEOM_EdgeSource() +{ +} + +void +GEOM_EdgeSource:: +AddEdge(const TopoDS_Edge& theEdge) +{ + myEdgeSet.Add(theEdge); +} + +void +GEOM_EdgeSource:: +Execute() +{ + vtkPolyData* aPolyData = GetOutput(); + aPolyData->Allocate(); + vtkPoints* aPts = vtkPoints::New(); + aPolyData->SetPoints(aPts); + aPts->Delete(); + + TEdgeSet::Iterator anIter(myEdgeSet); + for(; anIter.More(); anIter.Next()){ + const TopoDS_Edge& anEdge = anIter.Value(); + OCC2VTK(anEdge,aPolyData,aPts); + } +} + +void +GEOM_EdgeSource:: +OCC2VTK(const TopoDS_Edge& theEdge, + vtkPolyData* thePolyData, + vtkPoints* thePts) +{ + Handle(Poly_PolygonOnTriangulation) aEdgePoly; + Standard_Integer i = 1; + Handle(Poly_Triangulation) T; + TopLoc_Location aEdgeLoc; + BRep_Tool::PolygonOnTriangulation(theEdge, aEdgePoly, T, aEdgeLoc, i); + + Handle(Poly_Polygon3D) P; + if(aEdgePoly.IsNull()) + P = BRep_Tool::Polygon3D(theEdge, aEdgeLoc); + + if(P.IsNull() && aEdgePoly.IsNull()) + return; + + // Location edges + //--------------- + gp_Trsf edgeTransf; + Standard_Boolean isidtrsf = true; + if(!aEdgeLoc.IsIdentity()) { + isidtrsf = false; + edgeTransf = aEdgeLoc.Transformation(); + } + + if (aEdgePoly.IsNull()) { + Standard_Integer aNbNodes = P->NbNodes(); + const TColgp_Array1OfPnt& aNodesP = P->Nodes(); + + for(int j = 1; j < aNbNodes; j++){ + gp_Pnt pt1 = aNodesP(j); + gp_Pnt pt2 = aNodesP(j+1); + + if(!isidtrsf) { + // apply edge transformation + pt1.Transform(edgeTransf); + pt2.Transform(edgeTransf); + } + + float aCoord1[3] = {pt1.X(), pt1.Y(), pt1.Z()}; + vtkIdType anIds[2]; + anIds[0] = thePts->InsertNextPoint(aCoord1); + + float aCoord2[3] = {pt2.X(), pt2.Y(), pt2.Z()}; + anIds[1] = thePts->InsertNextPoint(aCoord2); + + thePolyData->InsertNextCell(VTK_LINE,2,anIds); + } + } else { + Standard_Integer aNbNodes = aEdgePoly->NbNodes(); + const TColStd_Array1OfInteger& aNodeIds = aEdgePoly->Nodes(); + const TColgp_Array1OfPnt& anId2Pnts = T->Nodes(); + + for(int j = 1; j < aNbNodes; j++) { + Standard_Integer id1 = aNodeIds(j); + Standard_Integer id2 = aNodeIds(j+1); + + gp_Pnt pt1 = anId2Pnts(id1); + gp_Pnt pt2 = anId2Pnts(id2); + + if(!isidtrsf) { + // apply edge transformation + pt1.Transform(edgeTransf); + pt2.Transform(edgeTransf); + } + + float aCoord1[3] = {pt1.X(), pt1.Y(), pt1.Z()}; + vtkIdType anIds[2]; + anIds[0] = thePts->InsertNextPoint(aCoord1); + + float aCoord2[3] = {pt2.X(), pt2.Y(), pt2.Z()}; + anIds[1] = thePts->InsertNextPoint(aCoord2); + + thePolyData->InsertNextCell(VTK_LINE,2,anIds); + } + } +} \ No newline at end of file diff --git a/src/OBJECT/GEOM_EdgeSource.h b/src/OBJECT/GEOM_EdgeSource.h new file mode 100755 index 000000000..9471e045f --- /dev/null +++ b/src/OBJECT/GEOM_EdgeSource.h @@ -0,0 +1,43 @@ +#ifndef GEOM_EDGESOURCE_H +#define GEOM_EDGESOURCE_H + +#include "GEOM_DeviceActor.h" + +#include +#include + +typedef NCollection_Set TEdgeSet; + +#include + + +class VTK_EXPORT GEOM_EdgeSource: public vtkPolyDataSource +{ +public: + vtkTypeMacro(GEOM_EdgeSource,vtkPolyDataSource); + static GEOM_EdgeSource* New(); + + void AddEdge(const TopoDS_Edge& theEdge); + void Clear(){ myEdgeSet.Clear();} + + static + void OCC2VTK(const TopoDS_Edge& theEdge, + vtkPolyData* thePolyData, + vtkPoints* thePts); + +protected: + TEdgeSet myEdgeSet; + + void Execute(); + + GEOM_EdgeSource(); + ~GEOM_EdgeSource(); + +private: + // Not implememnted + GEOM_EdgeSource(const GEOM_EdgeSource&); + void operator=(const GEOM_EdgeSource&); +}; + + +#endif //GEOM_EDGESOURCE_H diff --git a/src/OBJECT/GEOM_FaceSource.cxx b/src/OBJECT/GEOM_FaceSource.cxx new file mode 100755 index 000000000..4f0d9145e --- /dev/null +++ b/src/OBJECT/GEOM_FaceSource.cxx @@ -0,0 +1,44 @@ +#include "GEOM_FaceSource.h" + +#include + +#include +#include + +#include +#include + +GEOM_FaceSource::GEOM_FaceSource() +{ +} + +GEOM_FaceSource::~GEOM_FaceSource() +{ +} + +void +GEOM_FaceSource:: +AddFace(const TopoDS_Face& theFace) +{ + myFaceSet.Add(theFace); +} + +void +GEOM_FaceSource:: +MoveTo(gp_Pnt thePnt, + vtkPoints* thePts) +{ + thePts->InsertNextPoint(thePnt.X(), thePnt.Y(), thePnt.Z()); +} + +void +GEOM_FaceSource:: +DrawTo(gp_Pnt thePnt, + vtkPolyData* thePolyData, + vtkPoints* thePts) +{ + vtkIdType anId = + thePts->InsertNextPoint(thePnt.X(), thePnt.Y(), thePnt.Z()); + vtkIdType anIds[2] = {anId-1, anId}; + thePolyData->InsertNextCell(VTK_LINE,2,anIds); +} diff --git a/src/OBJECT/GEOM_FaceSource.h b/src/OBJECT/GEOM_FaceSource.h new file mode 100755 index 000000000..8c03167af --- /dev/null +++ b/src/OBJECT/GEOM_FaceSource.h @@ -0,0 +1,47 @@ +#ifndef GEOM_FACESOURCE_H +#define GEOM_FACESOURCE_H + +#include "GEOM_DeviceActor.h" + +#include +#include +#include + +typedef NCollection_Set TFaceSet; + +#include + +class GEOM_FaceSource; +typedef GEOM_SmartPtr PFaceSource; + + +class VTK_EXPORT GEOM_FaceSource: public vtkPolyDataSource +{ +public: + vtkTypeMacro(GEOM_FaceSource,vtkPolyDataSource); + + void AddFace(const TopoDS_Face& theFace); + void Clear(){ myFaceSet.Clear();} + +protected: + TFaceSet myFaceSet; + + static + void MoveTo(gp_Pnt thePnt, + vtkPoints* thePts); + static + void DrawTo(gp_Pnt thePnt, + vtkPolyData* thePolyData, + vtkPoints* thePts); + + GEOM_FaceSource(); + ~GEOM_FaceSource(); + +private: + // Not implememnted + GEOM_FaceSource(const GEOM_FaceSource&); + void operator=(const GEOM_FaceSource&); +}; + + +#endif //GEOM_FACESOURCE_H diff --git a/src/OBJECT/GEOM_ShadingFace.cxx b/src/OBJECT/GEOM_ShadingFace.cxx new file mode 100755 index 000000000..1795bf0c2 --- /dev/null +++ b/src/OBJECT/GEOM_ShadingFace.cxx @@ -0,0 +1,84 @@ +#include "GEOM_ShadingFace.h" + +#include + +#include +#include + +#include +#include + +#include +#include + + +vtkStandardNewMacro(GEOM_ShadingFace); + +GEOM_ShadingFace::GEOM_ShadingFace() +{ +} + +GEOM_ShadingFace::~GEOM_ShadingFace() +{ +} + +void +GEOM_ShadingFace:: +Execute() +{ + vtkPolyData* aPolyData = GetOutput(); + aPolyData->Allocate(); + vtkPoints* aPts = vtkPoints::New(); + aPolyData->SetPoints(aPts); + aPts->Delete(); + + TFaceSet::Iterator anIter(myFaceSet); + for(; anIter.More(); anIter.Next()){ + const TopoDS_Face& aFace = anIter.Value(); + OCC2VTK(aFace,aPolyData,aPts); + } +} + +void +GEOM_ShadingFace:: +OCC2VTK(const TopoDS_Face& theFace, + vtkPolyData* thePolyData, + vtkPoints* thePts) +{ + TopLoc_Location aLoc; + Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(theFace,aLoc); + if(aPoly.IsNull()) + return; + else{ + gp_Trsf myTransf; + Standard_Boolean identity = true; + if(!aLoc.IsIdentity()){ + identity = false; + myTransf = aLoc.Transformation(); + } + + Standard_Integer i; + int aNbOfNodes = thePts->GetNumberOfPoints(); + const TColgp_Array1OfPnt& Nodes = aPoly->Nodes(); + Standard_Integer nbNodesInFace = aPoly->NbNodes(); + for(i = 1; i <= nbNodesInFace; i++) { + gp_Pnt P = Nodes(i); + if(!identity) + P.Transform(myTransf); + thePts->InsertNextPoint(P.X(),P.Y(),P.Z()); + } + + const Poly_Array1OfTriangle& Triangles = aPoly->Triangles(); + Standard_Integer nbTriInFace = aPoly->NbTriangles(); + for(i = 1; i <= nbTriInFace; i++){ + // Get the triangle + Standard_Integer N1,N2,N3; + Triangles(i).Get(N1,N2,N3); + N1 += aNbOfNodes - 1; + N2 += aNbOfNodes - 1; + N3 += aNbOfNodes - 1; + vtkIdType anIds[3] = {N1, N2, N3}; + thePolyData->InsertNextCell(VTK_TRIANGLE,3,anIds); + } + } +} \ No newline at end of file diff --git a/src/OBJECT/GEOM_ShadingFace.h b/src/OBJECT/GEOM_ShadingFace.h new file mode 100755 index 000000000..4414f9f29 --- /dev/null +++ b/src/OBJECT/GEOM_ShadingFace.h @@ -0,0 +1,31 @@ +#ifndef GEOM_SHADINGFACE_H +#define GEOM_SHADINGFACE_H + +#include "GEOM_FaceSource.h" + + +class VTK_EXPORT GEOM_ShadingFace: public GEOM_FaceSource +{ +public: + vtkTypeMacro(GEOM_ShadingFace,GEOM_FaceSource); + static GEOM_ShadingFace* New(); + + static + void OCC2VTK(const TopoDS_Face& theFace, + vtkPolyData* theCells, + vtkPoints* thePts); + +protected: + void Execute(); + + GEOM_ShadingFace(); + ~GEOM_ShadingFace(); + +private: + // Not implememnted + GEOM_ShadingFace(const GEOM_ShadingFace&); + void operator=(const GEOM_ShadingFace&); +}; + + +#endif //GEOM_SHADINGFACE_H diff --git a/src/OBJECT/GEOM_SmartPtr.h b/src/OBJECT/GEOM_SmartPtr.h new file mode 100755 index 000000000..886a085b8 --- /dev/null +++ b/src/OBJECT/GEOM_SmartPtr.h @@ -0,0 +1,33 @@ +#ifndef GEOM_SMARTPTR_H +#define GEOM_SMARTPTR_H + +#include + +template +class GEOM_SmartPtr: public vtkSmartPointer +{ +public: + GEOM_SmartPtr() {} + GEOM_SmartPtr(T* r, bool theIsOwner = false): vtkSmartPointer(r) { + if(r && theIsOwner) + r->Delete(); + } + GEOM_SmartPtr& operator()(T* r, bool theIsOwner = false){ + vtkSmartPointer::operator=(r); + if(r && theIsOwner) + r->Delete(); + return *this; + } + GEOM_SmartPtr& operator=(T* r){ vtkSmartPointer::operator=(r); return *this;} + T* Get() const { return this->GetPointer();} +}; + + +class GEOM_DeviceActor; +typedef GEOM_SmartPtr PDeviceActor; + +class vtkPolyDataMapper; +typedef GEOM_SmartPtr PPolyDataMapper; + + +#endif //GEOM_SMARTPTR_H diff --git a/src/OBJECT/GEOM_VertexSource.cxx b/src/OBJECT/GEOM_VertexSource.cxx new file mode 100755 index 000000000..50277626b --- /dev/null +++ b/src/OBJECT/GEOM_VertexSource.cxx @@ -0,0 +1,56 @@ +#include "GEOM_VertexSource.h" + +#include + +#include +#include +#include +#include + +#include +#include + +vtkStandardNewMacro(GEOM_VertexSource); + +GEOM_VertexSource::GEOM_VertexSource() +{ +} + +GEOM_VertexSource::~GEOM_VertexSource() +{ +} + +void +GEOM_VertexSource:: +AddVertex(const TopoDS_Vertex& theVertex) +{ + myVertexSet.Add(theVertex); +} + +void +GEOM_VertexSource:: +Execute() +{ + vtkPolyData* aPolyData = GetOutput(); + aPolyData->Allocate(); + vtkPoints* aPts = vtkPoints::New(); + aPolyData->SetPoints(aPts); + aPts->Delete(); + + TVertexSet::Iterator anIter(myVertexSet); + for(; anIter.More(); anIter.Next()){ + const TopoDS_Vertex& aVertex = anIter.Value(); + OCC2VTK(aVertex,aPolyData,aPts); + } +} + +void +GEOM_VertexSource:: +OCC2VTK(const TopoDS_Vertex& theVertex, + vtkPolyData* thePolyData, + vtkPoints* thePts) +{ + gp_Pnt aPnt = BRep_Tool::Pnt(theVertex); + vtkIdType anId = thePts->InsertNextPoint(aPnt.X(),aPnt.Y(),aPnt.Z()); + thePolyData->InsertNextCell(VTK_VERTEX,1,&anId); +} diff --git a/src/OBJECT/GEOM_VertexSource.h b/src/OBJECT/GEOM_VertexSource.h new file mode 100755 index 000000000..46a64f0de --- /dev/null +++ b/src/OBJECT/GEOM_VertexSource.h @@ -0,0 +1,43 @@ +#ifndef GEOM_VERTEXSOURCE_H +#define GEOM_VERTEXSOURCE_H + +#include "GEOM_DeviceActor.h" + +#include +#include + +typedef NCollection_Set TVertexSet; + +#include + + +class VTK_EXPORT GEOM_VertexSource: public vtkPolyDataSource +{ +public: + vtkTypeMacro(GEOM_VertexSource,vtkPolyDataSource); + static GEOM_VertexSource* New(); + + void AddVertex(const TopoDS_Vertex& theVertex); + void Clear(){ myVertexSet.Clear();} + + static + void OCC2VTK(const TopoDS_Vertex& theVertex, + vtkPolyData* thePolyData, + vtkPoints* thePts); + +protected: + TVertexSet myVertexSet; + + void Execute(); + + GEOM_VertexSource(); + ~GEOM_VertexSource(); + +private: + // Not implememnted + GEOM_VertexSource(const GEOM_VertexSource&); + void operator=(const GEOM_VertexSource&); +}; + + +#endif //GEOM_VERTEXSOURCE_H diff --git a/src/OBJECT/GEOM_WireframeFace.cxx b/src/OBJECT/GEOM_WireframeFace.cxx new file mode 100755 index 000000000..8d49a177c --- /dev/null +++ b/src/OBJECT/GEOM_WireframeFace.cxx @@ -0,0 +1,466 @@ +#include "GEOM_WireframeFace.h" + +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +vtkStandardNewMacro(GEOM_WireframeFace); + +GEOM_WireframeFace::GEOM_WireframeFace(): + NbIso(1), + Discret(15) +{ +} + +GEOM_WireframeFace::~GEOM_WireframeFace() +{ +} + +void +GEOM_WireframeFace:: +Execute() +{ + vtkPolyData* aPolyData = GetOutput(); + aPolyData->Allocate(); + vtkPoints* aPts = vtkPoints::New(); + aPolyData->SetPoints(aPts); + aPts->Delete(); + + TFaceSet::Iterator anIter(myFaceSet); + for(; anIter.More(); anIter.Next()){ + const TopoDS_Face& aFace = anIter.Value(); + OCC2VTK(aFace,aPolyData,aPts,NbIso,Discret); + } +} + +void +GEOM_WireframeFace:: +OCC2VTK(const TopoDS_Face& theFace, + vtkPolyData* thePolyData, + vtkPoints* thePts, + const int theNbIso, + const int theDiscret) +{ + TopoDS_Face aFace = theFace; + aFace.Orientation(TopAbs_FORWARD); + CreateIso(aFace,theNbIso,theDiscret,thePolyData,thePts); +} + +void +GEOM_WireframeFace:: +CreateIso(const TopoDS_Face& theFace, + const int theNbIso, + const int theDiscret, + vtkPolyData* thePolyData, + vtkPoints* thePts) +{ + // Constants for iso building + static Standard_Real INTERSECTOR_CONFUSION = 1.e-10 ; // -8 ; + static Standard_Real INTERSECTOR_TANGENCY = 1.e-10 ; // -8 ; + + static Standard_Real HATHCER_CONFUSION_2D = 1.e-8 ; + static Standard_Real HATHCER_CONFUSION_3D = 1.e-8 ; + + Geom2dHatch_Hatcher + aHatcher(Geom2dHatch_Intersector(INTERSECTOR_CONFUSION, + INTERSECTOR_TANGENCY), + HATHCER_CONFUSION_2D, + HATHCER_CONFUSION_3D, + Standard_True, + Standard_False); + + Standard_Real anUMin, anUMax, aVMin, aVMax; + TColStd_Array1OfReal anUPrm(1, theNbIso), aVPrm(1, theNbIso); + TColStd_Array1OfInteger anUInd(1, theNbIso), aVInd(1, theNbIso); + + anUInd.Init(0); + aVInd.Init(0); + + //----------------------------------------------------------------------- + // If the Min Max bounds are infinite, there are bounded to Infinite + // value. + //----------------------------------------------------------------------- + BRepTools::UVBounds(theFace, anUMin, anUMax, aVMin, aVMax) ; + Standard_Boolean InfiniteUMin = Precision::IsNegativeInfinite (anUMin) ; + Standard_Boolean InfiniteUMax = Precision::IsPositiveInfinite (anUMax) ; + Standard_Boolean InfiniteVMin = Precision::IsNegativeInfinite (aVMin) ; + Standard_Boolean InfiniteVMax = Precision::IsPositiveInfinite (aVMax) ; + + static float VTKINFINITE = 1.0E38; + if(InfiniteUMin && InfiniteUMax){ + anUMin = - VTKINFINITE ; + anUMax = VTKINFINITE ; + }else if(InfiniteUMin){ + anUMin = anUMax - VTKINFINITE ; + }else if(InfiniteUMax){ + anUMax = anUMin + VTKINFINITE ; + } + + if(InfiniteVMin && InfiniteVMax){ + aVMin = - VTKINFINITE ; + aVMax = VTKINFINITE ; + }else if(InfiniteVMin){ + aVMin = aVMax - VTKINFINITE ; + }else if(InfiniteVMax){ + aVMax = aVMin + VTKINFINITE ; + } + + //----------------------------------------------------------------------- + // Retreiving the edges and loading them into the hatcher. + //----------------------------------------------------------------------- + TopExp_Explorer ExpEdges(theFace, TopAbs_EDGE); + for(; ExpEdges.More(); ExpEdges.Next()){ + const TopoDS_Edge& anEdge = TopoDS::Edge(ExpEdges.Current()); + Standard_Real U1, U2 ; + const Handle(Geom2d_Curve) PCurve = + BRep_Tool::CurveOnSurface(anEdge, theFace, U1, U2) ; + + if(PCurve.IsNull() || U1 == U2) + return; + + //-- Test if a TrimmedCurve is necessary + if(Abs(PCurve->FirstParameter()-U1) <= Precision::PConfusion() && + Abs(PCurve->LastParameter()-U2) <= Precision::PConfusion()) + { + aHatcher.AddElement(PCurve, anEdge.Orientation()) ; + }else{ + if(!PCurve->IsPeriodic()){ + Handle(Geom2d_TrimmedCurve) TrimPCurve = + Handle(Geom2d_TrimmedCurve)::DownCast(PCurve); + if(!TrimPCurve.IsNull()){ + Handle_Geom2d_Curve aBasisCurve = TrimPCurve->BasisCurve(); + if(aBasisCurve->FirstParameter()-U1 > Precision::PConfusion() || + U2-aBasisCurve->LastParameter() > Precision::PConfusion()) + { + aHatcher.AddElement(PCurve, anEdge.Orientation()) ; + return; + } + }else{ + if(PCurve->FirstParameter()-U1 > Precision::PConfusion()){ + U1=PCurve->FirstParameter(); + } + if(U2-PCurve->LastParameter() > Precision::PConfusion()){ + U2=PCurve->LastParameter(); + } + } + } + Handle(Geom2d_TrimmedCurve) TrimPCurve = + new Geom2d_TrimmedCurve(PCurve, U1, U2); + aHatcher.AddElement(TrimPCurve, anEdge.Orientation()); + } + } + + + //----------------------------------------------------------------------- + // Loading and trimming the hatchings. + //----------------------------------------------------------------------- + Standard_Integer IIso; + Standard_Real DeltaU = Abs(anUMax - anUMin) ; + Standard_Real DeltaV = Abs(aVMax - aVMin) ; + Standard_Real confusion = Min(DeltaU, DeltaV) * HATHCER_CONFUSION_3D ; + aHatcher.Confusion3d (confusion) ; + + Standard_Real StepU = DeltaU / (Standard_Real)theNbIso; + if(StepU > confusion){ + Standard_Real UPrm = anUMin + StepU / 2.; + gp_Dir2d Dir(0., 1.) ; + for(IIso = 1 ; IIso <= theNbIso ; IIso++) { + anUPrm(IIso) = UPrm ; + gp_Pnt2d Ori (UPrm, 0.) ; + Geom2dAdaptor_Curve HCur (new Geom2d_Line (Ori, Dir)) ; + anUInd(IIso) = aHatcher.AddHatching (HCur) ; + UPrm += StepU ; + } + } + + Standard_Real StepV = DeltaV / (Standard_Real) theNbIso ; + if(StepV > confusion){ + Standard_Real VPrm = aVMin + StepV / 2.; + gp_Dir2d Dir(1., 0.); + for(IIso = 1 ; IIso <= theNbIso ; IIso++){ + aVPrm(IIso) = VPrm; + gp_Pnt2d Ori (0., VPrm); + Geom2dAdaptor_Curve HCur(new Geom2d_Line (Ori, Dir)); + aVInd(IIso) = aHatcher.AddHatching (HCur) ; + VPrm += StepV ; + } + } + + //----------------------------------------------------------------------- + // Computation. + //----------------------------------------------------------------------- + aHatcher.Trim() ; + + Standard_Integer aNbDom = 0 ; // for debug purpose + for(IIso = 1 ; IIso <= theNbIso ; IIso++){ + Standard_Integer Index ; + + Index = anUInd(IIso) ; + if(Index != 0){ + if(aHatcher.TrimDone(Index) && !aHatcher.TrimFailed(Index)){ + aHatcher.ComputeDomains(Index); + if(aHatcher.IsDone (Index)) + aNbDom = aHatcher.NbDomains (Index); + } + } + + Index = aVInd(IIso); + if(Index != 0){ + if(aHatcher.TrimDone (Index) && !aHatcher.TrimFailed(Index)){ + aHatcher.ComputeDomains (Index); + if(aHatcher.IsDone (Index)) + aNbDom = aHatcher.NbDomains (Index); + } + } + } + + //----------------------------------------------------------------------- + // Push iso lines in vtk kernel + //----------------------------------------------------------------------- + for(Standard_Integer UIso = anUPrm.Lower() ; UIso <= anUPrm.Upper(); UIso++){ + Standard_Integer UInd = anUInd.Value(UIso); + if(UInd != 0){ + Standard_Real UPrm = anUPrm.Value(UIso); + if(aHatcher.IsDone(UInd)){ + Standard_Integer NbDom = aHatcher.NbDomains(UInd); + for(Standard_Integer IDom = 1 ; IDom <= NbDom ; IDom++){ + const HatchGen_Domain& Dom = aHatcher.Domain(UInd, IDom) ; + Standard_Real V1 = Dom.HasFirstPoint()? Dom.FirstPoint().Parameter(): aVMin - VTKINFINITE; + Standard_Real V2 = Dom.HasSecondPoint()? Dom.SecondPoint().Parameter(): aVMax + VTKINFINITE; + CreateIso_(theFace, GeomAbs_IsoU, UPrm, V1, V2, theDiscret, thePolyData, thePts); + } + } + } + } + + for(Standard_Integer VIso = aVPrm.Lower() ; VIso <= aVPrm.Upper(); VIso++){ + Standard_Integer VInd = aVInd.Value(VIso); + if(VInd != 0){ + Standard_Real VPrm = aVPrm.Value(VIso); + if(aHatcher.IsDone (VInd)){ + Standard_Integer NbDom = aHatcher.NbDomains(VInd); + for (Standard_Integer IDom = 1 ; IDom <= NbDom ; IDom++){ + const HatchGen_Domain& Dom = aHatcher.Domain(VInd, IDom); + Standard_Real U1 = Dom.HasFirstPoint()? Dom.FirstPoint().Parameter(): aVMin - VTKINFINITE; + Standard_Real U2 = Dom.HasSecondPoint()? Dom.SecondPoint().Parameter(): aVMax + VTKINFINITE; + CreateIso_(theFace, GeomAbs_IsoV, VPrm, U1, U2, theDiscret, thePolyData, thePts); + } + } + } + } +} + + + +void +GEOM_WireframeFace:: +CreateIso_(const TopoDS_Face& theFace, + GeomAbs_IsoType theIsoType, + Standard_Real Par, + Standard_Real T1, + Standard_Real T2, + const int theDiscret, + vtkPolyData* thePolyData, + vtkPoints* thePts) +{ + Standard_Real U1, U2, V1, V2, stepU=0., stepV=0.; + Standard_Integer j; + gp_Pnt P; + + TopLoc_Location aLoc; + const Handle(Geom_Surface)& S = BRep_Tool::Surface(theFace,aLoc); + + if(!S.IsNull()){ + BRepAdaptor_Surface S(theFace,Standard_False); + + GeomAbs_SurfaceType SurfType = S.GetType(); + + GeomAbs_CurveType CurvType = GeomAbs_OtherCurve; + + Standard_Integer Intrv, nbIntv; + Standard_Integer nbUIntv = S.NbUIntervals(GeomAbs_CN); + Standard_Integer nbVIntv = S.NbVIntervals(GeomAbs_CN); + TColStd_Array1OfReal TI(1,Max(nbUIntv, nbVIntv)+1); + + if(theIsoType == GeomAbs_IsoU){ + S.VIntervals(TI, GeomAbs_CN); + V1 = Max(T1, TI(1)); + V2 = Min(T2, TI(2)); + U1 = Par; + U2 = Par; + stepU = 0; + nbIntv = nbVIntv; + }else{ + S.UIntervals(TI, GeomAbs_CN); + U1 = Max(T1, TI(1)); + U2 = Min(T2, TI(2)); + V1 = Par; + V2 = Par; + stepV = 0; + nbIntv = nbUIntv; + } + + S.D0(U1,V1,P); + MoveTo(P,thePts); + + for(Intrv = 1; Intrv <= nbIntv; Intrv++){ + if(TI(Intrv) <= T1 && TI(Intrv + 1) <= T1) + continue; + if(TI(Intrv) >= T2 && TI(Intrv + 1) >= T2) + continue; + if(theIsoType == GeomAbs_IsoU){ + V1 = Max(T1, TI(Intrv)); + V2 = Min(T2, TI(Intrv + 1)); + stepV = (V2 - V1) / theDiscret; + }else{ + U1 = Max(T1, TI(Intrv)); + U2 = Min(T2, TI(Intrv + 1)); + stepU = (U2 - U1) / theDiscret; + } + + switch (SurfType) { + case GeomAbs_Plane : + break; + case GeomAbs_Cylinder : + case GeomAbs_Cone : + if(theIsoType == GeomAbs_IsoV){ + for(j = 1; j < theDiscret; j++){ + U1 += stepU; + V1 += stepV; + S.D0(U1,V1,P); + DrawTo(P,thePolyData,thePts); + } + } + break; + case GeomAbs_Sphere : + case GeomAbs_Torus : + case GeomAbs_OffsetSurface : + case GeomAbs_OtherSurface : + for(j = 1; j < theDiscret; j++){ + U1 += stepU; + V1 += stepV; + S.D0(U1,V1,P); + DrawTo(P,thePolyData,thePts); + } + break; + case GeomAbs_BezierSurface : + case GeomAbs_BSplineSurface : + for(j = 1; j <= theDiscret/2; j++){ + Standard_Real aStep = (theIsoType == GeomAbs_IsoV) ? stepU*2. : stepV*2.; + CreateIso__(S, theIsoType, U1, V1, aStep, thePolyData, thePts); + U1 += stepU*2.; + V1 += stepV*2.; + } + break; + case GeomAbs_SurfaceOfExtrusion : + case GeomAbs_SurfaceOfRevolution : + if((theIsoType == GeomAbs_IsoV && SurfType == GeomAbs_SurfaceOfRevolution) || + (theIsoType == GeomAbs_IsoU && SurfType == GeomAbs_SurfaceOfExtrusion)) + { + if(SurfType == GeomAbs_SurfaceOfExtrusion) + break; + for(j = 1; j < theDiscret; j++){ + U1 += stepU; + V1 += stepV; + S.D0(U1,V1,P); + DrawTo(P,thePolyData,thePts); + } + }else{ + CurvType = (S.BasisCurve())->GetType(); + switch(CurvType){ + case GeomAbs_Line : + break; + case GeomAbs_Circle : + case GeomAbs_Ellipse : + for (j = 1; j < theDiscret; j++) { + U1 += stepU; + V1 += stepV; + S.D0(U1,V1,P); + DrawTo(P,thePolyData,thePts); + } + break; + case GeomAbs_Parabola : + case GeomAbs_Hyperbola : + case GeomAbs_BezierCurve : + case GeomAbs_BSplineCurve : + case GeomAbs_OtherCurve : + for(j = 1; j <= theDiscret/2; j++){ + Standard_Real aStep = (theIsoType == GeomAbs_IsoV) ? stepU*2. : stepV*2.; + CreateIso__(S, theIsoType, U1, V1, aStep, thePolyData, thePts); + U1 += stepU*2.; + V1 += stepV*2.; + } + break; + } + } + } + } + S.D0(U2,V2,P); + DrawTo(P,thePolyData,thePts); + } +} + + + + +void +GEOM_WireframeFace:: +CreateIso__(const BRepAdaptor_Surface& theSurface, + GeomAbs_IsoType theIsoType, + Standard_Real& theU, + Standard_Real& theV, + Standard_Real theStep, + vtkPolyData* thePolyData, + vtkPoints* thePts) +{ + gp_Pnt Pl, Pr, Pm; + if (theIsoType == GeomAbs_IsoU) { + theSurface.D0(theU, theV, Pl); + theSurface.D0(theU, theV + theStep/2., Pm); + theSurface.D0(theU, theV + theStep, Pr); + } else { + theSurface.D0(theU, theV, Pl); + theSurface.D0(theU + theStep/2., theV, Pm); + theSurface.D0(theU + theStep, theV, Pr); + } + + static Standard_Real ISO_RATIO = 1.001; + if (Pm.Distance(Pl) + Pm.Distance(Pr) <= ISO_RATIO*Pl.Distance(Pr)) { + DrawTo(Pr,thePolyData,thePts); + } else { + if (theIsoType == GeomAbs_IsoU) { + CreateIso__(theSurface, theIsoType, theU, theV, theStep/2, thePolyData, thePts); + Standard_Real aLocalV = theV + theStep/2 ; + CreateIso__(theSurface, theIsoType, theU, aLocalV , theStep/2, thePolyData, thePts); + } else { + CreateIso__(theSurface, theIsoType, theU, theV, theStep/2, thePolyData, thePts); + Standard_Real aLocalU = theU + theStep/2 ; + CreateIso__(theSurface, theIsoType, aLocalU , theV, theStep/2, thePolyData, thePts); + } + } +} \ No newline at end of file diff --git a/src/OBJECT/GEOM_WireframeFace.h b/src/OBJECT/GEOM_WireframeFace.h new file mode 100755 index 000000000..cdbe122b3 --- /dev/null +++ b/src/OBJECT/GEOM_WireframeFace.h @@ -0,0 +1,75 @@ +#ifndef GEOM_WIREFRAME_FACE_H +#define GEOM_WIREFRAME_FACE_H + +#include "GEOM_FaceSource.h" + +#include +#include + +#include + + +class VTK_EXPORT GEOM_WireframeFace: public GEOM_FaceSource +{ +public: + vtkTypeMacro(GEOM_WireframeFace,GEOM_FaceSource); + static GEOM_WireframeFace* New(); + + vtkSetMacro(NbIso,int); + vtkGetMacro(NbIso,int); + + vtkSetMacro(Discret,int); + vtkGetMacro(Discret,int); + + static + void OCC2VTK(const TopoDS_Face& theFace, + vtkPolyData* thePolyData, + vtkPoints* thePts, + int theNbIso = 1, + int theDiscret = 15); + +protected: + int NbIso, Discret; + + static + void + CreateIso(const TopoDS_Face& theFace, + const int theNbIso, + const int theDiscret, + vtkPolyData* thePolyData, + vtkPoints* thePts); + + static + void + CreateIso_(const TopoDS_Face& theFace, + GeomAbs_IsoType theIsoType, + Standard_Real Par, + Standard_Real T1, + Standard_Real T2, + const int theDiscret, + vtkPolyData* thePolyData, + vtkPoints* thePts); + + static + void + CreateIso__(const BRepAdaptor_Surface& theSurface, + GeomAbs_IsoType theIsoType, + Standard_Real& theU, + Standard_Real& theV, + Standard_Real theStep, + vtkPolyData* thePolyData, + vtkPoints* thePts); + + void Execute(); + + GEOM_WireframeFace(); + ~GEOM_WireframeFace(); + +private: + // Not implememnted + GEOM_WireframeFace(const GEOM_WireframeFace&); + void operator=(const GEOM_WireframeFace&); +}; + + +#endif //GEOM_WFACEACTOR_H diff --git a/src/OBJECT/Makefile.am b/src/OBJECT/Makefile.am index 3d3e0dacb..638ff6ac4 100644 --- a/src/OBJECT/Makefile.am +++ b/src/OBJECT/Makefile.am @@ -39,7 +39,14 @@ salomeinclude_HEADERS = \ GEOM_AISTrihedron.hxx \ GEOM_VTKTrihedron.hxx \ GEOM_AISVector.hxx \ - GEOM_OBJECT_defs.hxx + GEOM_OBJECT_defs.hxx \ + GEOM_SmartPtr.h \ + GEOM_DeviceActor.h \ + GEOM_EdgeSource.h \ + GEOM_FaceSource.h \ + GEOM_ShadingFace.h \ + GEOM_VertexSource.h \ + GEOM_WireframeFace.h # Libraries targets lib_LTLIBRARIES = libGEOMObject.la @@ -52,7 +59,13 @@ dist_libGEOMObject_la_SOURCES = \ GEOM_InteractiveObject.cxx \ GEOM_AISTrihedron.cxx \ GEOM_VTKTrihedron.cxx \ - GEOM_AISVector.cxx + GEOM_AISVector.cxx \ + GEOM_DeviceActor.cxx \ + GEOM_EdgeSource.cxx \ + GEOM_FaceSource.cxx \ + GEOM_ShadingFace.cxx \ + GEOM_VertexSource.cxx \ + GEOM_WireframeFace.cxx libGEOMObject_la_CPPFLAGS = \