Fix for Bug NPAL12883

This commit is contained in:
enk 2007-10-18 05:19:08 +00:00
parent faef7428c3
commit f20c2e1db2
20 changed files with 2153 additions and 385 deletions

View File

@ -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();
}

View File

@ -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<SVTK_Prs*>( 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

View File

@ -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,10 +304,12 @@ void GEOMToolsGUI::OnTransparency()
void GEOMToolsGUI::OnNbIsos()
{
SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
if ( !isOCC )
return;
bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
const bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
// if is OCCViewer
if(isOCC){
OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
Handle (AIS_InteractiveContext) ic = vm->getAISContext();
@ -343,6 +345,66 @@ void GEOMToolsGUI::OnNbIsos()
}
}
}
} 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<SVTK_ViewWindow*>( 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<GEOM_Actor*>(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<GEOM_Actor*>(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()

View File

@ -30,202 +30,494 @@
\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 <vtkObjectFactory.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolyDataNormals.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 <vtkObjectFactory.h>
#include <vtkRenderer.h>
#include <vtkProperty.h>
#include <vtkPointPicker.h>
#include <vtkCellPicker.h>
#include <TopAbs_ShapeEnum.hxx>
#include <TopExp_Explorer.hxx>
#include <Poly_Triangulation.hxx>
#include <BRepMesh_IncrementalMesh.hxx>
#include <Bnd_Box.hxx>
#include <TopoDS.hxx>
#include <BRep_Tool.hxx>
#include <BRepBndLib.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopExp.hxx>
#include <vtkPolyDataWriter.h>
#include <vtkAppendPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolyData.h>
#include <vtkTransform.h>
#include <vtkMatrix4x4.h>
#include <vtkMath.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkCamera.h>
// OpenCASCADE Includes
#include "GEOM_OCCReader.h"
#include <BRep_Tool.hxx>
//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())
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;
#ifdef MYDEBUG
cout <<this<< " GEOM_Actor::GEOM_Actor"<<endl;
#endif
myPolyDataMapper->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()
{
this->Device = vtkActor::New();
this->WireframeMapper = NULL;
this->ShadingMapper = NULL;
this->ShadingProperty = NULL;
this->WireframeProperty = NULL;
this->deflection = 0;
myDisplayMode = 0;
this->myIO = NULL;
this->myName = "";
this->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();
#ifdef MYDEBUG
cout <<this<< " ~GEOM_Actor::GEOM_Actor"<<endl;
#endif
myHighlightProp->Delete();
myPreHighlightProp->Delete();
myShadingFaceProp->Delete();
}
void GEOM_Actor::ShallowCopy(vtkProp *prop)
GEOM_Actor*
GEOM_Actor::
New()
{
GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
if ( f != NULL )
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 - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells()<<endl;
aWriter->SetInput(theDataSet);
aWriter->SetFileName(theFileName);
//aWriter->Write();
aWriter->Delete();
}
void
GEOM_Actor::
SetModified()
{
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;
this->myVertexSource->Modified();
this->myIsolatedEdgeSource->Modified();
this->myOneFaceEdgeSource->Modified();
this->mySharedEdgeSource->Modified();
this->myWireframeFaceSource->Modified();
this->myShadingFaceSource->Modified();
}
// Now do superclass
this->SALOME_Actor::ShallowCopy(prop);
void
GEOM_Actor::
SetMapper(vtkMapper* theMapper)
{
SALOME_Actor::SetMapper(theMapper);
}
//-------------------------------------------------------------
// Set parameters
//-------------------------------------------------------------
void
GEOM_Actor::
AddToRender(vtkRenderer* theRenderer)
{
//SALOME_Actor::AddToRender(theRenderer);
theRenderer->AddActor(this);
this->myHighlightActor->AddToRender(theRenderer);
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();
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 = "<<theMode <<endl;
#endif
VTKViewer_Actor::setDisplayMode(theMode);
SetVisibility(GetVisibility());
}
void
GEOM_Actor::
SetSelected(bool theIsSelected)
{
#ifdef MYDEBUG
cout << "GEOM_Actor::SetSelected = "<<theIsSelected <<endl;
#endif
myIsSelected = theIsSelected;
SetVisibility(GetVisibility());
}
void
GEOM_Actor::
SetVisibility(int theVisibility)
{
#ifdef MYDEBUG
cout << "GEOM_Actor::SetVisibility = "<<theVisibility <<" myIsSelected="<< myIsSelected
<< " theVisibility="<<theVisibility<<" myIsPreselected="<<myIsPreselected<<endl;
#endif
SALOME_Actor::SetVisibility(theVisibility);
this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
// if(myDisplayMode == (int)eShading)
// this->myHighlightActor->SetInput(myShadingFaceSource->GetOutput(),false);
// else
// this->myHighlightActor->SetInput(myAppendFilter->GetOutput(),false);
myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading) && (!myIsSelected || !myIsPreselected));
myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode ==(int)eWireframe) && !myIsSelected);
mySharedEdgeActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);
myOneFaceEdgeActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);
myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
myVertexActor->SetVisibility(false);// must be added new mode points
}
void
GEOM_Actor
::SetNbIsos(const int theNb[2])
{
myNbIsos[0] = theNb[0];
myNbIsos[1] = theNb[1];
}
void
GEOM_Actor
::GetNbIsos(int &theNbU,int &theNbV)
{
theNbU = myNbIsos[0];
theNbV = myNbIsos[1];
}
static
void
MeshShape(const TopoDS_Shape& theShape,
float& theDeflection,
bool theIsRelative)
{
static Standard_Real RELATIVE_DEFLECTION = 0.0001;
Standard_Real aDeflection = theDeflection;
if(theDeflection <= 0) { // Compute default theDeflection
Bnd_Box B;
BRepBndLib::Add(theShape, B);
Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
Standard_Real aDiagonal = (aXmax-aXmin)*(aXmax-aXmin) +
(aYmax-aYmin)*(aYmax-aYmin) +
(aZmax-aZmin)*(aZmax-aZmin);
aDiagonal = sqrt(aDiagonal);
aDeflection = aDiagonal*RELATIVE_DEFLECTION;
if(theIsRelative)
theDeflection = RELATIVE_DEFLECTION;
else
return;
} else
CreateShadingMapper();
} else
CreateWireframeMapper();
theDeflection = aDeflection;
}
void GEOM_Actor::setDeflection(double adef) {
deflection = adef;
BRepMesh_IncrementalMesh aMesh(theShape,aDeflection);
}
void GEOM_Actor::setInputShape(const TopoDS_Shape& aShape, double adef,
int imode, bool isVector)
void
GEOM_Actor::
SetDeflection(float theDeflection, bool theIsRelative)
{
myShape = aShape;
deflection = adef;
myIsVector = isVector;
setDisplayMode(imode);
myDeflection = theDeflection;
myIsRelative = theIsRelative;
MeshShape(myShape,myDeflection,myIsRelative);
SetModified();
}
//-------------------------------------------------------------
// Get parameters
//-------------------------------------------------------------
void
GEOM_Actor::
SetShape(const TopoDS_Shape& theShape,
float theDeflection,
bool theIsRelative)
{
myShape = theShape;
const TopoDS_Shape& GEOM_Actor::getTopo() {
return myShape;
myVertexSource->Clear();
myIsolatedEdgeSource->Clear();
myOneFaceEdgeSource->Clear();
mySharedEdgeSource->Clear();
myWireframeFaceSource->Clear();
myShadingFaceSource->Clear();
TopExp_Explorer aVertexExp(theShape,TopAbs_VERTEX);
for(; aVertexExp.More(); aVertexExp.Next()){
const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
myVertexSource->AddVertex(aVertex);
}
SetDeflection(theDeflection,theIsRelative);
// look if edges are free or shared
TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
SetShape(theShape,anEdgeMap);
}
double GEOM_Actor::getDeflection() {
return deflection;
void
GEOM_Actor::
SetShape(const TopoDS_Shape& theShape,
const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap)
{
if(theShape.ShapeType() == TopAbs_COMPOUND) {
TopoDS_Iterator anItr(theShape);
for(; anItr.More(); anItr.Next()) {
SetShape(anItr.Value(),theEdgeMap);
}
}
void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop) {
this->WireframeProperty = Prop;
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);
}
}
}
}
}
}
}
void GEOM_Actor::SetShadingProperty(vtkProperty* Prop) {
this->ShadingProperty = Prop;
// OLD METHODS
void GEOM_Actor::setDeflection(double adef) {
#ifdef MYDEBUG
cout << "GEOM_Actor::setDeflection"<<endl;
#endif
SetDeflection((float)adef,GetIsRelative());
}
//-------------------------------------------------------------
// 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();
// warning! must be checked!
// SetHighlightProperty
// SetWireframeProperty
// SetShadingProperty
void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
{
#ifdef MYDEBUG
cout << "GEOM_Actor::SetHighlightProperty"<<endl;
#endif
this->myHighlightActor->GetProperty()->DeepCopy(Prop);
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::SetWireframeProperty(vtkProperty* Prop)
{
#ifdef MYDEBUG
cout << this << " GEOM_Actor::SetWireframeProperty"<<endl;
#endif
// must be filled
myWireframeFaceActor->SetProperty(Prop);
}
void GEOM_Actor::CreateWireframeMapper() {
CreateMapper(0);
void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
{
#ifdef MYDEBUG
cout << "GEOM_Actor::SetShadingProperty"<<endl;
#endif
myShadingFaceProp->DeepCopy(Prop);
}
//-------------------------------------------------------------
// Render function
//-------------------------------------------------------------
void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *Mapper)
{
#ifdef MYDEBUG
cout << "GEOM_Actor::Render"<<endl;
#endif
if(!GetVisibility())
return;
/* render the property */
if (!this->Property) {
// force creation of a property
@ -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"<<endl;
#endif
}
void GEOM_Actor::ShallowCopy(vtkProp *prop)
{
#ifdef MYDEBUG
cout << "GEOM_Actor::ShallowCopy"<<endl;
#endif
GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
if ( f != NULL )
{
this->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"<<endl;
#endif
return myShape;
}
void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
int imode, bool isVector)
{
#ifdef MYDEBUG
cout << "GEOM_Actor::setInputShape"<<endl;
#endif
}
double GEOM_Actor::getDeflection()
{
#ifdef MYDEBUG
cout << "GEOM_Actor::getDeflection"<<endl;
#endif
return (double) GetDeflection();
}
double GEOM_Actor::isVector()
{
#ifdef MYDEBUG
cout << "GEOM_Actor::isVector"<<endl;
#endif
return 0;
}
void GEOM_Actor::SubShapeOn()
{
subshape = true;
}
void GEOM_Actor::SubShapeOff()
{
subshape = false;
#ifdef MYDEBUG
cout << "GEOM_Actor::SubShapeOn"<<endl;
#endif
}
//-------------------------------------------------------------
// Opacity methods
//-------------------------------------------------------------
void GEOM_Actor::SubShapeOff()
{
#ifdef MYDEBUG
cout << "GEOM_Actor::SubShapeOff"<<endl;
#endif
}
void GEOM_Actor::highlight(bool highlight)
{
#ifdef MYDEBUG
cout << "GEOM_Actor::highlight highlight="<<highlight<<endl;
#endif
SALOME_Actor::highlight(highlight);
}
void GEOM_Actor::SetOpacity(vtkFloatingPointType opa)
{
//HighlightProperty->SetOpacity(opa);
SALOME_Actor::SetOpacity(opa);
ShadingProperty->SetOpacity(opa);
// enk:tested OK
myShadingFaceProp->SetOpacity(opa);
myHighlightProp->SetOpacity(opa);
myPreHighlightProp->SetOpacity(opa);
}
vtkFloatingPointType GEOM_Actor::GetOpacity() {
return ShadingProperty->GetOpacity();
}
//-------------------------------------------------------------
// Color methods
//-------------------------------------------------------------
void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b) {
ShadingProperty->SetColor(r,g,b);
}
void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b) {
vtkFloatingPointType color[3];
ShadingProperty->GetColor(color);
r = color[0];
g = color[1];
b = color[2];
}
//-------------------------------------------------------------
// Highlight methods
//-------------------------------------------------------------
void GEOM_Actor::highlight(bool highlight) {
if(highlight && !myIsHighlighted) {
myIsHighlighted=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(myIsHighlighted) {
myIsHighlighted=false;
if(myDisplayMode==1) {
//unhilight in shading
this->Property = ShadingProperty;
}
else {
//unhilight in wireframe
this->Property = WireframeProperty;
}
}
}
}
void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop) {
this->HighlightProperty = Prop;
}
void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *renWin)
vtkFloatingPointType GEOM_Actor::GetOpacity()
{
vtkActor::ReleaseGraphicsResources(renWin);
// broadcast the message down to the individual LOD mappers
if(WireframeMapper) this->WireframeMapper->ReleaseGraphicsResources(renWin);
if(ShadingMapper) this->ShadingMapper->ReleaseGraphicsResources(renWin);
// enk:tested OK
return myShadingFaceProp->GetOpacity();
}
void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
{
// enk:tested OK
myShadingFaceProp->SetColor(r,g,b);
}
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];
}
bool GEOM_Actor::IsInfinite()
{
return (bool)(myShape.Infinite());
}
/*!
To map current selection to VTK representation
*/
void
GEOM_Actor
::Highlight(bool theIsHighlight)
{
myIsSelected = theIsHighlight;
#ifdef MYDEBUG
cout << "GEOM_Actor::Highlight myIsSelected="<<myIsSelected<<endl;
#endif
SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
SetVisibility(GetVisibility());
}
/*!
To process prehighlight (called from SVTK_InteractorStyle)
*/
bool
GEOM_Actor
::PreHighlight(vtkInteractorStyle *theInteractorStyle,
SVTK_SelectionEvent* theSelectionEvent,
bool theIsHighlight)
{
#ifdef MYDEBUG
cout << "this="<<this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight<<endl;
#endif
if ( !GetPickable() )
return false;
myPreHighlightActor->SetVisibility( false );
bool anIsPreselected = myIsPreselected;
Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
bool anIsChanged = (mySelectionMode != aSelectionMode);
if( !theIsHighlight ) {
SetPreSelected( false );
}else{
switch(aSelectionMode){
case ActorSelection :
{
if( !mySelector->IsSelected( myIO ) ) {
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
cout << endl << "GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected<<endl;
#endif
bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
SetSelected(theIsHighlight);
return aRet;
}
// Copy the follower's composite 4x4 matrix into the matrix provided.
void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)

View File

@ -33,57 +33,88 @@
#include "SALOME_Actor.h"
//OpenCASCADE
#include <TopoDS_Shape.hxx>
#include <TopoDS.hxx>
class vtkCamera;
class TopoDS_Shape;
#include "GEOM_SmartPtr.h"
#include <vtkSmartPointer.h>
class GEOM_OBJECT_EXPORT GEOM_Actor : public SALOME_Actor {
class GEOM_VertexSource;
typedef GEOM_SmartPtr<GEOM_VertexSource> PVertexSource;
class GEOM_EdgeSource;
typedef GEOM_SmartPtr<GEOM_EdgeSource> PEdgeSource;
class GEOM_WireframeFace;
typedef GEOM_SmartPtr<GEOM_WireframeFace> PWFaceSource;
class GEOM_ShadingFace;
typedef GEOM_SmartPtr<GEOM_ShadingFace> PSFaceSource;
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
class vtkRenderer;
class vtkAppendPolyData;
typedef GEOM_SmartPtr<vtkAppendPolyData> PAppendFilter;
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);
enum EDisplayMode{ eWireframe, eShading};
/* void SetDisplayMode(EDisplayMode theMode); */
/* EDisplayMode GetDisplayMode() const { return myDisplayMode;} */
void SetSelected(bool theIsSelected);
bool IsSelected() const { return myIsSelected;}
// 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;}
virtual bool IsInfinite();
// 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 GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result);
GEOM_Actor();
~GEOM_Actor();
GEOM_Actor(const GEOM_Actor&) {};
void operator=(const GEOM_Actor&) {};
void CreateWireframeMapper();
void CreateShadingMapper();
void CreateMapper(int theMode);
void GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result);
private:
bool subshape;
bool myIsInfinite;
TopoDS_Shape myShape;
double deflection;
bool myIsVector;
int myNbIsos[2];
vtkMapper* ShadingMapper;
vtkMapper* WireframeMapper;
float myDeflection;
bool myIsRelative;
bool myIsForced;
vtkProperty* ShadingProperty;
vtkProperty* WireframeProperty;
vtkProperty* HighlightProperty;
// 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<vtkProperty> myHighlightProp;
vtkSmartPointer<vtkProperty> myPreHighlightProp;
vtkSmartPointer<vtkProperty> myShadingFaceProp;
PAppendFilter myAppendFilter;
PPolyDataMapper myPolyDataMapper;
virtual void SetMapper(vtkMapper*);
GEOM_Actor(const GEOM_Actor&);
void operator=(const GEOM_Actor&);
};
#endif //GEOM_ACTOR_H

View File

@ -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();
@ -419,6 +440,8 @@ vtkAssembly* GEOM_AssemblyBuilder::BuildAssembly(const TopoDS_Shape& myShape,
myVTKShape->AddPart(myFaceAssembly);
}
*/
return myVTKShape;
}

83
src/OBJECT/GEOM_DeviceActor.cxx Executable file
View File

@ -0,0 +1,83 @@
#include "GEOM_DeviceActor.h"
#include <vtkObjectFactory.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkStripper.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolyDataNormals.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
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());
}

60
src/OBJECT/GEOM_DeviceActor.h Executable file
View File

@ -0,0 +1,60 @@
#ifndef GEOM_DEVICEACTOR_H
#define GEOM_DEVICEACTOR_H
#include "GEOM_SmartPtr.h"
class vtkPoints;
typedef GEOM_SmartPtr<vtkPoints> PPoints;
class vtkPolyData;
typedef GEOM_SmartPtr<vtkPolyData> PPolyData;
class vtkStripper;
typedef GEOM_SmartPtr<vtkStripper> PStripper;
class vtkPolyDataNormals;
typedef GEOM_SmartPtr<vtkPolyDataNormals> PPolyDataNormals;
class vtkActor;
typedef GEOM_SmartPtr<vtkActor> PActor;
class vtkProperty;
class vtkRenderer;
#include <vtkObject.h>
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

130
src/OBJECT/GEOM_EdgeSource.cxx Executable file
View File

@ -0,0 +1,130 @@
#include "GEOM_EdgeSource.h"
#include <vtkObjectFactory.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <BRep_Tool.hxx>
#include <Poly_Polygon3D.hxx>
#include <Poly_Triangulation.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <Poly_PolygonOnTriangulation.hxx>
#include <vtkStripper.h>
#include <vtkPolyData.h>
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);
}
}
}

43
src/OBJECT/GEOM_EdgeSource.h Executable file
View File

@ -0,0 +1,43 @@
#ifndef GEOM_EDGESOURCE_H
#define GEOM_EDGESOURCE_H
#include "GEOM_DeviceActor.h"
#include <TopoDS_Edge.hxx>
#include <NCollection_Set.hxx>
typedef NCollection_Set<TopoDS_Edge> TEdgeSet;
#include <vtkPolyDataSource.h>
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

44
src/OBJECT/GEOM_FaceSource.cxx Executable file
View File

@ -0,0 +1,44 @@
#include "GEOM_FaceSource.h"
#include <vtkObjectFactory.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolyData.h>
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);
}

47
src/OBJECT/GEOM_FaceSource.h Executable file
View File

@ -0,0 +1,47 @@
#ifndef GEOM_FACESOURCE_H
#define GEOM_FACESOURCE_H
#include "GEOM_DeviceActor.h"
#include <gp_Pnt.hxx>
#include <TopoDS_Face.hxx>
#include <NCollection_Set.hxx>
typedef NCollection_Set<TopoDS_Face> TFaceSet;
#include <vtkPolyDataSource.h>
class GEOM_FaceSource;
typedef GEOM_SmartPtr<GEOM_FaceSource> 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

84
src/OBJECT/GEOM_ShadingFace.cxx Executable file
View File

@ -0,0 +1,84 @@
#include "GEOM_ShadingFace.h"
#include <vtkObjectFactory.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolyData.h>
#include <BRep_Tool.hxx>
#include <Poly_Triangulation.hxx>
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);
}
}
}

31
src/OBJECT/GEOM_ShadingFace.h Executable file
View File

@ -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

33
src/OBJECT/GEOM_SmartPtr.h Executable file
View File

@ -0,0 +1,33 @@
#ifndef GEOM_SMARTPTR_H
#define GEOM_SMARTPTR_H
#include <vtkSmartPointer.h>
template <class T>
class GEOM_SmartPtr: public vtkSmartPointer<T>
{
public:
GEOM_SmartPtr() {}
GEOM_SmartPtr(T* r, bool theIsOwner = false): vtkSmartPointer<T>(r) {
if(r && theIsOwner)
r->Delete();
}
GEOM_SmartPtr& operator()(T* r, bool theIsOwner = false){
vtkSmartPointer<T>::operator=(r);
if(r && theIsOwner)
r->Delete();
return *this;
}
GEOM_SmartPtr& operator=(T* r){ vtkSmartPointer<T>::operator=(r); return *this;}
T* Get() const { return this->GetPointer();}
};
class GEOM_DeviceActor;
typedef GEOM_SmartPtr<GEOM_DeviceActor> PDeviceActor;
class vtkPolyDataMapper;
typedef GEOM_SmartPtr<vtkPolyDataMapper> PPolyDataMapper;
#endif //GEOM_SMARTPTR_H

View File

@ -0,0 +1,56 @@
#include "GEOM_VertexSource.h"
#include <vtkObjectFactory.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <gp_Pnt.hxx>
#include <BRep_Tool.hxx>
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);
}

43
src/OBJECT/GEOM_VertexSource.h Executable file
View File

@ -0,0 +1,43 @@
#ifndef GEOM_VERTEXSOURCE_H
#define GEOM_VERTEXSOURCE_H
#include "GEOM_DeviceActor.h"
#include <TopoDS_Vertex.hxx>
#include <NCollection_Set.hxx>
typedef NCollection_Set<TopoDS_Vertex> TVertexSet;
#include <vtkPolyDataSource.h>
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

466
src/OBJECT/GEOM_WireframeFace.cxx Executable file
View File

@ -0,0 +1,466 @@
#include "GEOM_WireframeFace.h"
#include <vtkObjectFactory.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolyData.h>
#include <Precision.hxx>
#include <BRepTools.hxx>
#include <TopExp_Explorer.hxx>
#include <Geom2dHatch_Hatcher.hxx>
#include <Geom2dHatch_Intersector.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <BRep_Tool.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <Geom2d_Line.hxx>
#include <gp_Dir2d.hxx>
#include <gp_Pnt2d.hxx>
#include <Geom2dHatch_Hatcher.hxx>
#include <HatchGen_Domain.hxx>
#include <Adaptor3d_HCurve.hxx>
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);
}
}
}

75
src/OBJECT/GEOM_WireframeFace.h Executable file
View File

@ -0,0 +1,75 @@
#ifndef GEOM_WIREFRAME_FACE_H
#define GEOM_WIREFRAME_FACE_H
#include "GEOM_FaceSource.h"
#include <GeomAbs_IsoType.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <vtkPolyDataSource.h>
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

View File

@ -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 = \