X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FOBJECT%2FGEOM_Actor.cxx;h=9b956bf68619c68e24455218a7ee0aeb988ff6d7;hb=357991964c4929ef01edcf1d55eddd67f8512c29;hp=0602bc5caa36c4c2a42156b062364548e1f7a4da;hpb=8403de181549f67834cfd0dcd0747af511cbd3dd;p=modules%2Fgeom.git diff --git a/src/OBJECT/GEOM_Actor.cxx b/src/OBJECT/GEOM_Actor.cxx index 0602bc5ca..9b956bf68 100644 --- a/src/OBJECT/GEOM_Actor.cxx +++ b/src/OBJECT/GEOM_Actor.cxx @@ -1,212 +1,532 @@ -// GEOM OBJECT : interactive object for Geometry entities visualization +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// GEOM OBJECT : interactive object for Geometry entities visualization // File : GEOM_Actor.cxx // Author : Christophe ATTANASIO // Module : GEOM // $Header$ - -using namespace std; +// /*! \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 "GEOM_PainterPolyDataMapper.h" +#include "SVTK_Actor.h" -#include "GEOM_Actor.h" +#include -// OpenCASCADE Includes -#include "GEOM_OCCReader.h" +#include +#include +#include +#include +#include + +#include +#include +#include #include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include -//------------------------------------------------------------- -// Main methods -//------------------------------------------------------------- +#include "utilities.h" +#include "SALOME_InteractiveObject.hxx" -GEOM_Actor* GEOM_Actor::New() -{ - // First try to create the object from the vtkObjectFactory - vtkObject* ret = vtkObjectFactory::CreateInstance("GEOM_Actor"); - if(ret) - { - return (GEOM_Actor*)ret; - } - // If the factory was unable to create the object, then create it here. - return new GEOM_Actor; -} +//vtkStandardNewMacro(GEOM_Actor); +#ifndef MYDEBUG +//#define MYDEBUG +#endif -GEOM_Actor::GEOM_Actor() -{ - this->Device = vtkActor::New(); +GEOM_Actor::GEOM_Actor(): + isOnlyVertex(false), - this->WireframeMapper = NULL; - this->ShadingMapper = NULL; + myDeflection(-1), + myIsForced(false), - this->ShadingProperty = NULL; - this->WireframeProperty = NULL; + // myDisplayMode(eWireframe), + myIsSelected(false), + myVectorMode(false), - this->deflection = 0; - myDisplayMode = 0; + 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), + // Use mapper as an instance of GEOM_PainterPolyDataMapper class + // to prevent drawing of mappers' content (due to an empty definition + // of GEOM_PainterPolyDataMapper::RenderPiece(...)). + // !!! Presentation of GEOM_Actor is drawing only with help of actors + // defined in this class !!! + myPolyDataMapper(GEOM_PainterPolyDataMapper::New(),true), - this->myIO = NULL; - this->myName = ""; + myHighlightProp(vtkProperty::New()), + myPreHighlightProp(vtkProperty::New()), + myShadingFaceProp(vtkProperty::New()), + myShadingBackFaceProp(vtkProperty::New()) +{ +#ifdef MYDEBUG + MESSAGE (this<< " GEOM_Actor::GEOM_Actor"); +#endif - this->HighlightProperty = NULL; - this->ishighlighted = false; + myPolyDataMapper->SetInput(myAppendFilter->GetOutput()); + vtkProperty* aProperty; - this->subshape = false; -} + 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); + myHighlightProp->SetPointSize(SALOME_POINT_SIZE); + 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); -GEOM_Actor::~GEOM_Actor() + myShadingFaceProp->SetRepresentation(VTKViewer::Representation::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()); + + StoreBoundaryColors(); + + myNbIsos[0] = -1; + myNbIsos[1] = -1; + + // Toggle display mode + setDisplayMode(0); // WIRE FRAME + SetVectorMode(0); // +} + + +GEOM_Actor::~GEOM_Actor() +{ +#ifdef MYDEBUG + MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor"); +#endif + myHighlightProp->Delete(); + myPreHighlightProp->Delete(); + myShadingFaceProp->Delete(); + myShadingBackFaceProp->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(); + MESSAGE ("Write - "<GetNumberOfPoints()<<"; "<GetNumberOfCells()); + aWriter->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) { - 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(); + //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); -void GEOM_Actor::ShallowCopy(vtkProp *prop) -{ - GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop); - if ( f != NULL ) - { - this->setInputShape(f->getTopo(),f->getDeflection(),f->getDisplayMode()); - this->setName( f->getName() ); - if ( f->hasIO() ) - this->setIO( f->getIO() ); - this->ShadingMapper = NULL; - this->WireframeMapper = NULL; + 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 + MESSAGE ( "GEOM_Actor::setDisplayMode = "<GetProperty()->SetColor(myEdgesInShadingColor[0], + myEdgesInShadingColor[1], + myEdgesInShadingColor[2]); + myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0], + myEdgesInShadingColor[1], + myEdgesInShadingColor[2]); + mySharedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0], + myEdgesInShadingColor[1], + myEdgesInShadingColor[2]); + //SetModified(); } else { - this->myIO = NULL; - this->myName = ""; - this->ShadingMapper = NULL; - this->WireframeMapper = NULL; + myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0], + myEdgesInWireframeColor[1], + myEdgesInWireframeColor[2]); } + } - // Now do superclass - this->SALOME_Actor::ShallowCopy(prop); + VTKViewer_Actor::setDisplayMode(theMode); + SetVisibility(GetVisibility()); +} + +void +GEOM_Actor:: +SetSelected(bool theIsSelected) +{ +#ifdef MYDEBUG + MESSAGE ( "GEOM_Actor::SetSelected = "<WireframeProperty = Prop; + +// warning! must be checked! +// SetHighlightProperty +// SetWireframeProperty +// SetShadingProperty + +void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop) +{ +#ifdef MYDEBUG + MESSAGE ( "GEOM_Actor::SetHighlightProperty" ); +#endif + this->myHighlightActor->GetProperty()->DeepCopy(Prop); + } -void GEOM_Actor::SetShadingProperty(vtkProperty* Prop) { - this->ShadingProperty = Prop; +void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop) +{ +#ifdef MYDEBUG + MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" ); +#endif + // must be filled + myWireframeFaceActor->SetProperty(Prop); } -//------------------------------------------------------------- -// Mapper creating function -//------------------------------------------------------------- -void GEOM_Actor::CreateMapper(int theMode) { - 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); - 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); +vtkProperty* GEOM_Actor::GetWireframeProperty() +{ + return myWireframeFaceActor->GetProperty(); } -void GEOM_Actor::CreateShadingMapper() { - CreateMapper(1); +void GEOM_Actor::SetShadingProperty(vtkProperty* Prop) +{ +#ifdef MYDEBUG + MESSAGE ( "GEOM_Actor::SetShadingProperty" ); +#endif + myShadingFaceProp->DeepCopy(Prop); } -void GEOM_Actor::CreateWireframeMapper() { - CreateMapper(0); +vtkProperty* GEOM_Actor::GetShadingProperty() +{ + return myShadingFaceProp; } -//------------------------------------------------------------- -// Render function -//------------------------------------------------------------- -void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *Mapper) +void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper) { +#ifdef MYDEBUG + MESSAGE ( "GEOM_Actor::Render" ); +#endif + + if(!GetVisibility()) + return; + /* render the property */ if (!this->Property) { // force creation of a property @@ -219,17 +539,33 @@ void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *Mapper) this->Property->SetSpecularColor(0.99,0.98,0.83); } - if(!ishighlighted) { - if(myDisplayMode >= 1) { - // SHADING - this->Property = ShadingProperty; - } - else { - this->Property = WireframeProperty; - } + switch(myDisplayMode){ + case eWireframe://wireframe + myPreHighlightProp->SetRepresentationToWireframe(); + myHighlightProp->SetRepresentationToWireframe(); + break; + case eShading://shading + case eShadingWithEdges://shading with edges + myPreHighlightProp->SetRepresentationToSurface(); + myHighlightProp->SetRepresentationToSurface(); + break; + } - if ( ispreselected ) - this->Property = PreviewProperty; + if(!myIsSelected){ + if(myIsPreselected){ + this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer()); + myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer()); + myShadingFaceActor->SetBackfaceProperty(myPreHighlightProp.GetPointer()); + } else { + this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer()); + myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer()); + myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer()); + } + } + else{ + this->myHighlightActor->SetProperty(myHighlightProp.GetPointer()); + myShadingFaceActor->SetProperty(myHighlightProp.GetPointer()); + myShadingFaceActor->SetBackfaceProperty(myHighlightProp.GetPointer()); } this->Property->Render(this, ren); @@ -238,31 +574,13 @@ 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(myShape.ShapeType() == TopAbs_VERTEX) { if(ren){ //The parameter determine size of vertex actor relate to diagonal of RendererWindow - static float delta = 0.01; - float X1 = -1, Y1 = -1, Z1 = 0; + static vtkFloatingPointType delta = 0.01; + vtkFloatingPointType X1 = -1, Y1 = -1, Z1 = 0; ren->ViewToWorld(X1,Y1,Z1); - float X2 = +1, Y2 = +1, Z2 = 0; + vtkFloatingPointType X2 = +1, Y2 = +1, Z2 = 0; ren->ViewToWorld(X2,Y2,Z2); Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1)); this->SetScale(Z2*delta); @@ -270,112 +588,325 @@ void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *Mapper) vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New(); this->GetMatrix(ren->GetActiveCamera(), aMatrix); this->Device->SetUserMatrix(aMatrix); - this->Device->Render(ren,this->Mapper); + this->Device->Render(ren,theMapper); aMatrix->Delete(); - } else - this->Device->Render(ren, this->Mapper); - if(WireframeMapper!=NULL) this->EstimatedRenderTime = WireframeMapper->GetTimeToDraw(); - else if(ShadingMapper!=NULL) this->EstimatedRenderTime = ShadingMapper->GetTimeToDraw(); + } else*/ + this->Device->Render(ren, theMapper); +} + +void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *) +{ +#ifdef MYDEBUG + MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" ); +#endif +} + + + +void GEOM_Actor::ShallowCopy(vtkProp *prop) +{ +#ifdef MYDEBUG + MESSAGE ( "GEOM_Actor::ShallowCopy" ); +#endif + GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop); + if ( f != NULL ) + { + this->SetShape(f->getTopo(),f->GetDeflection()); + } + + // Now do superclass + this->SALOME_Actor::ShallowCopy(prop); +} + +const TopoDS_Shape& GEOM_Actor::getTopo() { +#ifdef MYDEBUG + MESSAGE ( "GEOM_Actor::getTopo" ); +#endif + return myShape; +} + +void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1, + int imode, bool isVector) +{ +#ifdef MYDEBUG + MESSAGE ( "GEOM_Actor::setInputShape" ); +#endif +} + +double GEOM_Actor::getDeflection() +{ +#ifdef MYDEBUG + MESSAGE ( "GEOM_Actor::getDeflection" ); +#endif + return (double) GetDeflection(); +} + + +double GEOM_Actor::isVector() +{ +#ifdef MYDEBUG + MESSAGE ( "GEOM_Actor::isVector" ); +#endif + return 0; } -// SubShape void GEOM_Actor::SubShapeOn() { - subshape = true; +#ifdef MYDEBUG + MESSAGE ( "GEOM_Actor::SubShapeOn" ); +#endif } + void GEOM_Actor::SubShapeOff() { - subshape = false; +#ifdef MYDEBUG + MESSAGE ( "GEOM_Actor::SubShapeOff" ); +#endif } -//------------------------------------------------------------- -// Opacity methods -//------------------------------------------------------------- +void GEOM_Actor::highlight(bool highlight) +{ +#ifdef MYDEBUG + MESSAGE ( this << " GEOM_Actor::highlight highlight="<SetOpacity(opa); - SALOME_Actor::SetOpacity(opa); - ShadingProperty->SetOpacity(opa); + // enk:tested OK + myShadingFaceProp->SetOpacity(opa); + myShadingBackFaceProp->SetOpacity(opa); + myHighlightProp->SetOpacity(opa); + myPreHighlightProp->SetOpacity(opa); + myVertexActor->GetProperty()->SetOpacity(opa); } -float GEOM_Actor::GetOpacity() { - return ShadingProperty->GetOpacity(); +vtkFloatingPointType GEOM_Actor::GetOpacity() +{ + // enk:tested OK + return myShadingFaceProp->GetOpacity(); } -//------------------------------------------------------------- -// Color methods -//------------------------------------------------------------- -void GEOM_Actor::SetColor(float r,float g,float b) { - ShadingProperty->SetColor(r,g,b); +void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b) +{ + // enk:tested OK + myShadingFaceProp->SetColor(r,g,b); // shading color (Shading) + myShadingBackFaceProp->SetColor(r,g,b); // back face shading color (Shading) + myVertexActor->GetProperty()->SetColor(r,g,b); // vertex actor (Shading/Wireframe) + if ( myDisplayMode != (int)eShadingWithEdges ) { + myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b); // standalone edge color (Wireframe) + myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b); // standalone face edge color (Wireframe) + mySharedEdgeActor->GetProperty()->SetColor(r,g,b); // share edge color (Wireframe) + } + + StoreBoundaryColors(); } -void GEOM_Actor::GetColor(float& r,float& g,float& b) { - float color[3]; - ShadingProperty->GetColor(color); - r = color[0]; - g = color[1]; - b = color[2]; +void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b) +{ + // enk:tested OK + vtkFloatingPointType aRGB[3]; + myShadingFaceProp->GetColor(aRGB); + r = aRGB[0]; + g = aRGB[1]; + b = aRGB[2]; } -//------------------------------------------------------------- -// Highlight methods -//------------------------------------------------------------- +void GEOM_Actor::SetMaterial(std::vector theProps) +{ + int aSize = theProps.size(); -void GEOM_Actor::highlight(Standard_Boolean highlight) { + if ( aSize < 1 || aSize > 2) + return; - if(highlight && !ishighlighted) { - ishighlighted=true; - // build highlight property is necessary - if(HighlightProperty==NULL) { - HighlightProperty = vtkProperty::New(); - HighlightProperty->SetAmbient(0.5); - HighlightProperty->SetDiffuse(0.3); - HighlightProperty->SetSpecular(0.2); - HighlightProperty->SetRepresentationToSurface(); - HighlightProperty->SetAmbientColor(1, 1, 1); - HighlightProperty->SetDiffuseColor(1, 1, 1); - HighlightProperty->SetSpecularColor(0.5, 0.5, 0.5); - } - - this->Property = HighlightProperty; - - } - else if (!highlight) { - if(ishighlighted) { - ishighlighted=false; - if(myDisplayMode==1) { - //unhilight in shading - this->Property = ShadingProperty; - } - else { - //unhilight in wireframe - this->Property = WireframeProperty; - } - } - } + // theProps[0] -- front material properties + // theProps[1] -- back material properties (if exist) + // If there are no back material properties, + // we get front material properties as back material + + double aCoefnt; + + // Set reflection coefficients + aCoefnt = theProps[0]->GetAmbient(); + myShadingFaceProp->SetAmbient(aCoefnt); + myVertexActor->GetProperty()->SetAmbient(aCoefnt); + if ( aSize == 2 ) + aCoefnt = theProps[1]->GetAmbient(); + myShadingBackFaceProp->SetAmbient(aCoefnt); + + // Set diffuse coefficients + aCoefnt = theProps[0]->GetDiffuse(); + myShadingFaceProp->SetDiffuse(aCoefnt); + myVertexActor->GetProperty()->SetDiffuse(aCoefnt); + if ( aSize == 2 ) + aCoefnt = theProps[1]->GetDiffuse(); + myShadingBackFaceProp->SetDiffuse(aCoefnt); + + // Set specular coefficients + aCoefnt = theProps[0]->GetSpecular(); + myShadingFaceProp->SetSpecular(aCoefnt); + myVertexActor->GetProperty()->SetSpecular(aCoefnt); + if ( aSize == 2 ) + aCoefnt = theProps[1]->GetSpecular(); + myShadingBackFaceProp->SetSpecular(aCoefnt); + + + double* aColor; + + // Set reflection colors + aColor = theProps[0]->GetAmbientColor(); + myShadingFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]); + myVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]); + if ( aSize == 2 ) + aColor = theProps[1]->GetAmbientColor(); + myShadingBackFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]); + + // Set diffuse colors + aColor = theProps[0]->GetDiffuseColor(); + myShadingFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]); + myVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]); + if ( aSize == 2 ) + aColor = theProps[1]->GetDiffuseColor(); + myShadingBackFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]); + + // Set specular colors + aColor = theProps[0]->GetSpecularColor(); + myShadingFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]); + myVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]); + if ( aSize == 2 ) + aColor = theProps[1]->GetSpecularColor(); + myShadingBackFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]); + + // Set shininess + aCoefnt = theProps[0]->GetSpecularPower(); + myShadingFaceProp->SetSpecularPower(aCoefnt); + myVertexActor->GetProperty()->SetSpecularPower(aCoefnt); + if ( aSize == 2 ) + aCoefnt = theProps[1]->GetSpecularPower(); + myShadingBackFaceProp->SetSpecularPower(aCoefnt); + + // Set back face material property + myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer()); } -bool GEOM_Actor::hasHighlight() +vtkProperty* GEOM_Actor::GetFrontMaterial() { - return true; + return myShadingFaceProp; } -void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop) { - this->HighlightProperty = Prop; +vtkProperty* GEOM_Actor::GetBackMaterial() +{ + return myShadingBackFaceProp; } +bool GEOM_Actor::IsInfinitive() +{ + return ((bool)myShape.Infinite() || isOnlyVertex); +} -void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *renWin) +/*! + To map current selection to VTK representation +*/ +void +GEOM_Actor +::Highlight(bool theIsHighlight) { - vtkActor::ReleaseGraphicsResources(renWin); + myIsSelected = theIsHighlight; +#ifdef MYDEBUG + MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<getEntry() << endl; +// int nbio = mySelector->IObjectCount(); +// cout << " nbio = " << nbio << endl; + + if( !mySelector->IsSelected( myIO ) ) { + // printf ("!!!!!!!!!!!!!!!!\n"); + SetPreSelected( true ); + } + } + default: + break; + } + } + + mySelectionMode = aSelectionMode; + anIsChanged |= (anIsPreselected != myIsPreselected); + + SetVisibility(GetVisibility()); + return anIsChanged; } +/*! + To process highlight (called from SVTK_InteractorStyle) +*/ +bool +GEOM_Actor +::Highlight(vtkInteractorStyle *theInteractorStyle, + SVTK_SelectionEvent* theSelectionEvent, + bool theIsHighlight) +{ + // define the selection of object +#ifdef MYDEBUG + MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<Position[0])*(pos[0] - this->Position[0]) + + (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) + (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) + (pos[2] - this->Position[2])*(pos[2] - this->Position[2])); for (i = 0; i < 3; i++) - { + { Rz[i] = (pos[i] - this->Position[i])/distance; - } + } } vtkMath::Cross(vup,Rz,Rx); @@ -463,3 +994,68 @@ void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result) matrix->Delete(); this->Transform->Pop(); } + +void GEOM_Actor::SetEdgesInShadingColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b) +{ + myEdgesInShadingColor[0] = r; + myEdgesInShadingColor[1] = g; + myEdgesInShadingColor[2] = b; +} + +void GEOM_Actor::StoreIsoNumbers() +{ + myWireframeFaceSource->GetNbIso(myNbIsos[0], myNbIsos[1]); +} + +void GEOM_Actor::SetIsosWidth(const int width) { + myWireframeFaceActor->GetProperty()->SetLineWidth(width); +} + +int GEOM_Actor::GetIsosWidth() const { + return myWireframeFaceActor->GetProperty()->GetLineWidth(); +} + +void GEOM_Actor::SetWidth(const int width) { + myIsolatedEdgeActor->GetProperty()->SetLineWidth(width); + myOneFaceEdgeActor->GetProperty()->SetLineWidth(width); + mySharedEdgeActor->GetProperty()->SetLineWidth(width); + myHighlightProp->SetLineWidth(width); + myPreHighlightProp->SetLineWidth(width+1); + +} + +int GEOM_Actor::GetWidth() const { + return myIsolatedEdgeActor->GetProperty()->GetLineWidth(); +} + +void GEOM_Actor::RestoreIsoNumbers() +{ + if ( myNbIsos[0] > 0 || myNbIsos[1] > 0 ) + // Restore number of U and (or) V iso lines + myWireframeFaceSource->SetNbIso(myNbIsos); +} + +void GEOM_Actor::ResetIsoNumbers() +{ + int aNb[2] = {0, 0}; + myWireframeFaceSource->SetNbIso(aNb); +} + +void GEOM_Actor::StoreBoundaryColors() +{ + myShadingFaceProp->GetColor(myEdgesInWireframeColor); + +} + +void GEOM_Actor::RestoreBoundaryColors() +{ + myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0], + myEdgesInWireframeColor[1], + myEdgesInWireframeColor[2]); + myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0], + myEdgesInWireframeColor[1], + myEdgesInWireframeColor[2]); + mySharedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0], + myEdgesInWireframeColor[1], + myEdgesInWireframeColor[2]); +}