VISU_VectorsAct.cxx
libVisuObject_la_CPPFLAGS= \
+ $(QT_INCLUDES) \
@CAS_CPPFLAGS@ @CAS_CXXFLAGS@ \
$(VTK_INCLUDES) \
$(BOOST_CPPFLAGS) \
#include <vtkProperty.h>
#include <vtkTexture.h>
#include <vtkPassThroughFilter.h>
+#include <vtkImageData.h>
+
+#include <qfileinfo.h>
#include "utilities.h"
+#include "VISU_PipeLineUtils.hxx"
#ifdef _DEBUG_
static int MYDEBUG = 0;
static int MYDEBUG = 0;
#endif
-using namespace std;
+
+//----------------------------------------------------------------
+namespace VISU
+{
+ inline
+ std::string
+ Image2VTI(const std::string& theImageFileName)
+ {
+ QFileInfo aFileInfo(theImageFileName.c_str());
+ QString aFormat = aFileInfo.extension(FALSE);
+#ifdef WIN32
+ QString aTmpDir = getenv( "TEMP" );
+#else
+ QString aTmpDir = QString( "/tmp/" ) + getenv("USER");
+#endif
+ QString aVTIName = aTmpDir + "-" + aFileInfo.baseName(TRUE) + ".vti";
+ QString aCommand = QString( "VISU_img2vti " ) + aFormat + " " + theImageFileName + " " + aVTIName;
+
+ if(system( aCommand.latin1() ) == 0)
+ return aVTIName.latin1();
+
+ return "";
+ }
+
+ inline
+ void
+ RemoveFile(const std::string& theFileName)
+ {
+ if( theFileName != "" ){
+#ifndef WNT
+ QString aCommand = QString( "rm -fr " ) + theFileName.c_str();
+#else
+ QString aCommand = QString( "del /F " ) + theFileName.c_str();
+#endif
+ system( aCommand.latin1() );
+ }
+ }
+
+
+ TTextureValue
+ GetTexture(const std::string& theMainTexture,
+ const std::string& theAlphaTexture)
+ {
+ typedef std::pair<std::string,std::string> TTextureKey;
+ typedef std::map<TTextureKey,TTextureValue> TTextureMap;
+
+ static TTextureMap aTextureMap;
+
+ TTextureValue aTextureValue;
+ TTextureKey aTextureKey( theMainTexture.c_str(), theAlphaTexture.c_str() );
+ TTextureMap::const_iterator anIter = aTextureMap.find( aTextureKey );
+ if ( anIter != aTextureMap.end() ) {
+ aTextureValue = anIter->second;
+ } else {
+ QString aMainTextureVTI = Image2VTI(theMainTexture);
+ QString anAlphaTextureVTI = Image2VTI(theAlphaTexture);
+
+ if( !aMainTextureVTI.isNull() && !anAlphaTextureVTI.isNull() ){
+ aTextureValue =
+ VISU_GaussPointsPL::MakeTexture( aMainTextureVTI.latin1(),
+ anAlphaTextureVTI.latin1());
+
+ if( aTextureValue.GetPointer() )
+ aTextureMap[aTextureKey] = aTextureValue;
+ }
+
+ RemoveFile(aMainTextureVTI);
+ RemoveFile(anAlphaTextureVTI);
+ }
+
+ return aTextureValue;
+ }
+}
//----------------------------------------------------------------
-vtkStandardNewMacro(VISU_GaussPtsDeviceActor);
+vtkStandardNewMacro(VISU_GaussDeviceActorBase);
-VISU_GaussPtsDeviceActor
-::VISU_GaussPtsDeviceActor():
- myGeomFilter(VTKViewer_GeometryFilter::New()),
+VISU_GaussDeviceActorBase
+::VISU_GaussDeviceActorBase():
myTransformFilter(VTKViewer_TransformFilter::New())
{
- if(MYDEBUG) MESSAGE("VISU_GaussPtsDeviceActor - "<<this);
+ if(MYDEBUG) MESSAGE("VISU_GaussDeviceActorBase - "<<this);
- myGeomFilter->Delete();
myTransformFilter->Delete();
for(int i = 0; i < 3; i++){
}
-VISU_GaussPtsDeviceActor
-::~VISU_GaussPtsDeviceActor()
+VISU_GaussDeviceActorBase
+::~VISU_GaussDeviceActorBase()
{
- if(MYDEBUG) MESSAGE("~VISU_GaussPtsDeviceActor - "<<this);
+ if(MYDEBUG) MESSAGE("~VISU_GaussDeviceActorBase - "<<this);
}
//----------------------------------------------------------------
void
-VISU_GaussPtsDeviceActor
+VISU_GaussDeviceActorBase
::Render(vtkRenderer *ren, vtkMapper *vtkNotUsed(m))
{
if (this->Mapper == NULL)
//----------------------------------------------------------------
void
-VISU_GaussPtsDeviceActor
-::AddToRender(vtkRenderer* theRenderer)
+VISU_GaussDeviceActorBase
+::SetTransform(VTKViewer_Transform* theTransform)
{
- theRenderer->AddActor(this);
+ myTransformFilter->SetTransform(theTransform);
}
-void
-VISU_GaussPtsDeviceActor
-::RemoveFromRender(vtkRenderer* theRenderer)
+//----------------------------------------------------------------
+void
+VISU_GaussDeviceActorBase
+::SetPointSpriteMapper(VISU_OpenGLPointSpriteMapper* theMapper)
{
- theRenderer->RemoveActor(this);
+ vtkPolyData* aDataSet = theMapper->GetInput();
+ myMapper = theMapper;
+
+ int anId = 0;
+ myPassFilter[ anId ]->SetInput( aDataSet );
+ myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
+
+ anId++;
+ myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
+
+ anId++;
+ myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
+
+ myMapper->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
+
+ Superclass::SetMapper( theMapper );
}
void
-VISU_GaussPtsDeviceActor
-::SetTransform(VTKViewer_Transform* theTransform)
+VISU_GaussDeviceActorBase
+::DoMapperShallowCopy( vtkMapper* theMapper,
+ bool theIsCopyInput )
{
- myTransformFilter->SetTransform(theTransform);
+ VISU::CopyMapper( GetMapper(), theMapper, theIsCopyInput );
}
VISU_OpenGLPointSpriteMapper*
-VISU_GaussPtsDeviceActor
+VISU_GaussDeviceActorBase
::GetPointSpriteMapper()
{
return myMapper.GetPointer();
//----------------------------------------------------------------------------
unsigned long int
-VISU_GaussPtsDeviceActor
+VISU_GaussDeviceActorBase
::GetMemorySize()
{
vtkDataSet* aDataSet = GetMapper()->GetInput();
- unsigned long int aSize = aDataSet->GetActualMemorySize() * 1024;
+ return aDataSet->GetActualMemorySize() * 1024;
+}
- aSize += GetPipeLine()->GetMemorySize();
- return aSize;
-}
+
+//----------------------------------------------------------------
+vtkStandardNewMacro(VISU_GaussPtsDeviceActor);
+
+
+VISU_GaussPtsDeviceActor
+::VISU_GaussPtsDeviceActor()
+{}
+
+
+VISU_GaussPtsDeviceActor
+::~VISU_GaussPtsDeviceActor()
+{}
+
//----------------------------------------------------------------------------
-int
+void
VISU_GaussPtsDeviceActor
-::GetPickable()
+::AddToRender(vtkRenderer* theRenderer)
{
- if(Superclass::GetPickable()){
- if(vtkMapper* aMapper = GetMapper()){
- if(vtkDataSet* aDataSet= aMapper->GetInput()){
- aDataSet->Update();
- return aDataSet->GetNumberOfCells() > 0;
- }
- }
- }
+ theRenderer->AddActor(this);
+}
- return false;
+void
+VISU_GaussPtsDeviceActor
+::RemoveFromRender(vtkRenderer* theRenderer)
+{
+ theRenderer->RemoveActor(this);
}
VISU_GaussPtsDeviceActor
::SetPipeLine(VISU_GaussPointsPL* thePipeLine)
{
- myPipeLine = thePipeLine;
- myMapper = thePipeLine->GetPointSpriteMapper();
- vtkPolyData* aDataSet = myMapper->GetInput();
+ SetPointSpriteMapper( thePipeLine->GetPointSpriteMapper() );
- int anId = 0;
- myPassFilter[ anId ]->SetInput( aDataSet );
- myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
-
- anId++;
- myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
-
- anId++;
- myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
-
- myMapper->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
-
- Superclass::SetMapper( myMapper.GetPointer() );
+ myPipeLine = thePipeLine;
}
VISU_GaussPointsPL*
}
+//----------------------------------------------------------------------------
+int
+VISU_GaussPtsDeviceActor
+::GetPickable()
+{
+ if(Superclass::GetPickable()){
+ if(vtkMapper* aMapper = GetMapper()){
+ if(vtkDataSet* aDataSet= aMapper->GetInput()){
+ aDataSet->Update();
+ return aDataSet->GetNumberOfCells() > 0;
+ }
+ }
+ }
+
+ return false;
+}
+
+
+//----------------------------------------------------------------------------
+unsigned long int
+VISU_GaussPtsDeviceActor
+::GetMemorySize()
+{
+ unsigned long int aSize = Superclass::GetMemorySize();
+
+ aSize += GetPipeLine()->GetMemorySize();
+
+ return aSize;
+}
+
+
+
//============================================================================
#include <vtkActor.h>
#include <vtkProperty.h>
#ifndef VISU_GAUSS_PTS_DEVICE_ACTOR_H
#define VISU_GAUSS_PTS_DEVICE_ACTOR_H
+#include "VISU_Actor.h"
#include "VTKViewer_GeometryFilter.h"
#include <vtkLODActor.h>
class VISU_GaussPointsPL;
class vtkPassThroughFilter;
+class vtkImageData;
+
//============================================================================
-class VISU_GaussPtsDeviceActor: public vtkLODActor
+namespace VISU
{
- public:
- vtkTypeMacro(VISU_GaussPtsDeviceActor,vtkLODActor);
+ typedef vtkSmartPointer<vtkImageData> TTextureValue;
+
+ VTKOCC_EXPORT
+ TTextureValue
+ GetTexture(const std::string& theMainTexture,
+ const std::string& theAlphaTexture);
+}
+
+//============================================================================
+class VISU_GaussDeviceActorBase: public vtkLODActor
+{
+ public:
+ vtkTypeMacro(VISU_GaussDeviceActorBase, vtkLODActor);
+
static
- VISU_GaussPtsDeviceActor*
+ VISU_GaussDeviceActorBase*
New();
virtual
//----------------------------------------------------------------------------
void
- AddToRender(vtkRenderer* theRenderer);
+ SetTransform(VTKViewer_Transform* theTransform);
+ //----------------------------------------------------------------------------
void
- RemoveFromRender(vtkRenderer* theRenderer);
+ SetPointSpriteMapper(VISU_OpenGLPointSpriteMapper* theMapper) ;
+ virtual
void
- SetTransform(VTKViewer_Transform* theTransform);
+ DoMapperShallowCopy( vtkMapper* theMapper,
+ bool theIsCopyInput );
+
+ VISU_OpenGLPointSpriteMapper*
+ GetPointSpriteMapper();
+
+ //----------------------------------------------------------------------------
+ //! Gets memory size used by the instance (bytes).
+ virtual
+ unsigned long int
+ GetMemorySize();
+
+ protected:
+ //----------------------------------------------------------------------------
+ vtkSmartPointer<VISU_OpenGLPointSpriteMapper> myMapper;
+ vtkSmartPointer<VTKViewer_TransformFilter> myTransformFilter;
+
+ typedef vtkSmartPointer<vtkPassThroughFilter> PPassThroughFilter;
+ std::vector<PPassThroughFilter> myPassFilter;
+
+ VISU_GaussDeviceActorBase();
+ ~VISU_GaussDeviceActorBase();
+
+ private:
+ VISU_GaussDeviceActorBase(const VISU_GaussDeviceActorBase&); // Not implemented
+ void operator=(const VISU_GaussDeviceActorBase&); // Not implemented
+};
+
+
+//============================================================================
+class VISU_GaussPtsDeviceActor: public VISU_GaussDeviceActorBase
+{
+ public:
+ vtkTypeMacro(VISU_GaussPtsDeviceActor, VISU_GaussDeviceActorBase);
+
+ static
+ VISU_GaussPtsDeviceActor*
+ New();
+
+ //----------------------------------------------------------------------------
+ void
+ AddToRender(vtkRenderer* theRenderer);
+
+ void
+ RemoveFromRender(vtkRenderer* theRenderer);
//----------------------------------------------------------------------------
VISU_GaussPointsPL*
void
ShallowCopyPL(VISU_GaussPointsPL* thePipeLine);
- VISU_OpenGLPointSpriteMapper*
- GetPointSpriteMapper();
+ virtual
+ int
+ GetPickable();
+ //----------------------------------------------------------------------------
//! Gets memory size used by the instance (bytes).
virtual
unsigned long int
GetMemorySize();
- virtual
- int
- GetPickable();
-
protected:
//----------------------------------------------------------------------------
vtkSmartPointer<VISU_GaussPointsPL> myPipeLine;
- vtkSmartPointer<VISU_OpenGLPointSpriteMapper> myMapper;
- vtkSmartPointer<VTKViewer_GeometryFilter> myGeomFilter;
- vtkSmartPointer<VTKViewer_TransformFilter> myTransformFilter;
-
- typedef vtkSmartPointer<vtkPassThroughFilter> PPassThroughFilter;
- std::vector<PPassThroughFilter> myPassFilter;
VISU_GaussPtsDeviceActor();
~VISU_GaussPtsDeviceActor();
#include "VISU_ScalarBarActor.hxx"
#include "VISU_PipeLine.hxx"
+#include "VISU_OpenGLPointSpriteMapper.hxx"
+#include "VISU_GaussPtsDeviceActor.h"
+#include "VISU_DeformedShapePL.hxx"
+#include "VISU_PipeLineUtils.hxx"
+
#include <vtkObjectFactory.h>
#include <vtkRenderer.h>
#include <vtkProperty.h>
#include <vtkMapper.h>
#include <vtkDataSetMapper.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkCallbackCommand.h>
+#include <vtkRenderWindow.h>
+#include <vtkImageData.h>
+
+
+//============================================================================
+class VISU_PointsDeviceActor: public VISU_GaussDeviceActorBase
+{
+ public:
+ vtkTypeMacro(VISU_PointsDeviceActor, VISU_GaussDeviceActorBase);
+
+ static
+ VISU_PointsDeviceActor*
+ New();
+
+
+ //----------------------------------------------------------------------------
+ virtual
+ void
+ SetInput(vtkDataSet* theDataSet)
+ {
+ myGeomFilter->SetInput( theDataSet );
+ }
+
+
+ //----------------------------------------------------------------------------
+ void
+ SetInteractor(vtkRenderWindowInteractor* theInteractor)
+ {
+ if(theInteractor == myInteractor)
+ return;
+
+ if(myInteractor)
+ myInteractor->RemoveObserver(myEventCallbackCommand);
+
+ if(theInteractor)
+ theInteractor->AddObserver(vtkCommand::CharEvent,
+ myEventCallbackCommand,
+ 0.0);
+
+ myInteractor = theInteractor;
+ }
+
+
+ //----------------------------------------------------------------------------
+ void
+ DoMapperShallowCopy( vtkMapper* theMapper,
+ bool theIsCopyInput )
+ {
+ Superclass::DoMapperShallowCopy( theMapper, theIsCopyInput );
+
+ vtkDataSet* aDataSet = theMapper->GetInput();
+ vtkFloatingPointType aScaleFactor = VISU_DeformedShapePL::GetScaleFactor( aDataSet );
+
+ GetPointSpriteMapper()->SetAverageCellSize( aScaleFactor );
+ }
+
+
+ //----------------------------------------------------------------------------
+ void
+ DeepCopy( VISU_PointsDeviceActor *theActor )
+ {
+ VISU::CopyPointSpriteDataMapper( GetPointSpriteMapper(), theActor->GetPointSpriteMapper(), false );
+ }
+
+ protected:
+ //----------------------------------------------------------------------------
+ VISU_PointsDeviceActor():
+ myGeomFilter( VTKViewer_GeometryFilter::New() ),
+ myEventCallbackCommand( vtkCallbackCommand::New() ),
+ myInteractor( NULL )
+ {
+ myGeomFilter->SetInside(true);
+
+ VISU_OpenGLPointSpriteMapper* aMapper = VISU_OpenGLPointSpriteMapper::New();
+ aMapper->SetInput( myGeomFilter->GetOutput() );
+
+ std::string aRootDir( getenv( "VISU_ROOT_DIR") );
+ std::string aMainTexture = aRootDir + "/share/salome/resources/visu/sprite_texture.bmp";
+ std::string anAlphaTexture = aRootDir + "/share/salome/resources/visu/sprite_alpha.bmp";
+ VISU::TTextureValue aTextureValue = VISU::GetTexture( aMainTexture, anAlphaTexture );
+ aMapper->SetImageData( aTextureValue.GetPointer() );
+
+ aMapper->SetUseLookupTableScalarRange(true);
+ aMapper->SetColorModeToMapScalars();
+ aMapper->SetScalarVisibility(true);
+
+ SetPointSpriteMapper( aMapper );
+
+ aMapper->Delete();
+
+ myEventCallbackCommand->SetClientData( this );
+ myEventCallbackCommand->SetCallback( VISU_PointsDeviceActor::ProcessEvents );
+ }
+
+
+ //----------------------------------------------------------------------------
+ ~VISU_PointsDeviceActor()
+ {
+ myGeomFilter->Delete();
+ myEventCallbackCommand->Delete();
+ }
+
+
+ //----------------------------------------------------------------------------
+ static
+ void
+ ProcessEvents(vtkObject* theObject,
+ unsigned long theEvent,
+ void* theClientData,
+ void* theCallData)
+ {
+ if ( vtkObject* anObject = reinterpret_cast<vtkObject*>( theClientData ) )
+ if ( VISU_PointsDeviceActor* self = dynamic_cast<VISU_PointsDeviceActor*>( anObject ) )
+ self->OnInteractorEvent( theEvent );
+ }
+
+
+ //----------------------------------------------------------------------------
+ void
+ OnInteractorEvent(unsigned long theEvent)
+ {
+ switch ( theEvent ) {
+ case vtkCommand::CharEvent: {
+ switch( myInteractor->GetKeyCode() ) {
+ case 'M' :
+ case 'm' : {
+ static vtkFloatingPointType anIncrement = 2;
+ vtkFloatingPointType aMagnification = GetPointSpriteMapper()->GetPointSpriteMagnification();
+ vtkFloatingPointType coefficient = myInteractor->GetShiftKey() ? anIncrement : 1 / anIncrement;
+
+ GetPointSpriteMapper()->SetPointSpriteMagnification( aMagnification * coefficient );
+
+ myInteractor->CreateTimer(VTKI_TIMER_UPDATE);
+ break;
+ }
+ default:
+ return;
+ }
+ break;
+ }
+ default:
+ return;
+ }
+ }
+
+
+ //----------------------------------------------------------------------------
+ vtkCallbackCommand* myEventCallbackCommand;
+ vtkRenderWindowInteractor* myInteractor;
+ VTKViewer_GeometryFilter* myGeomFilter;
+
+ private:
+ VISU_PointsDeviceActor(const VISU_PointsDeviceActor&); // Not implemented
+ void operator=(const VISU_PointsDeviceActor&); // Not implemented
+};
+
+vtkStandardNewMacro(VISU_PointsDeviceActor);
+
//----------------------------------------------------------------------------
vtkStandardNewMacro(VISU_ScalarMapAct);
static vtkFloatingPointType EPS = 1.0 / VTK_LARGE_FLOAT;
myEdgeActor->SetUserMatrix(m);
myEdgeActor->GetProperty()->SetColor(255.,255.,255.);
+ myPointsActor = VISU_PointsDeviceActor::New();
+ myPointsActor->SetUserMatrix(m);
+
m->Delete();
}
::~VISU_ScalarMapAct()
{
myScalarBar->Delete();
+
+ myPointsActor->Delete();
+
mySurfaceActor->Delete();
myEdgeActor->Delete();
}
VISU_ScalarMapAct
::ShallowCopyPL(VISU_PipeLine* thePipeLine)
{
- VISU_Actor::ShallowCopyPL(thePipeLine);
+ VISU_Actor::ShallowCopyPL( thePipeLine );
- myEdgeActor->GetMapper()->ScalarVisibilityOff();
+ myPointsActor->DoMapperShallowCopy( thePipeLine->GetMapper(), false );
- vtkDataSet* aDatsSet = mySurfaceActor->GetDataSetMapper()->GetInput();
- mySurfaceActor->GetMapper()->ShallowCopy(thePipeLine->GetMapper());
- // To restore mapper input from pipeline
- mySurfaceActor->GetDataSetMapper()->SetInput(aDatsSet);
+ VISU::CopyMapper( mySurfaceActor->GetMapper(), thePipeLine->GetMapper(), false );
}
//----------------------------------------------------------------------------
VISU_ScalarMapAct
::SetMapperInput(vtkDataSet* theDataSet)
{
- Superclass::SetMapperInput(theDataSet);
+ Superclass::SetMapperInput( theDataSet );
- mySurfaceActor->SetInput(theDataSet);
- myEdgeActor->SetInput(theDataSet);
+ myPointsActor->SetInput( theDataSet );
+
+ mySurfaceActor->SetInput( theDataSet );
+ myEdgeActor->SetInput( theDataSet );
}
//----------------------------------------------------------------------------
{
Superclass::SetTransform(theTransform);
+ myPointsActor->SetTransform(theTransform);
+
mySurfaceActor->SetTransform(theTransform);
myEdgeActor->SetTransform(theTransform);
}
if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
Superclass::DeepCopy(theActor);
SetBarVisibility(anActor->GetBarVisibility());
+ myPointsActor->DeepCopy( anActor->myPointsActor );
SetShading(anActor->IsShading());
}
}
{
Superclass::AddToRender(theRenderer);
+ myPointsActor->SetInteractor( myInteractor );
+
if(myScalarBar)
theRenderer->AddActor2D(myScalarBar);
}
if(myScalarBar)
theRenderer->RemoveActor(myScalarBar);
+ if ( vtkWindow* aWindow = theRenderer->GetRenderWindow() ) {
+ myPointsActor->ReleaseGraphicsResources( aWindow );
+ mySurfaceActor->ReleaseGraphicsResources( aWindow );
+ myEdgeActor->ReleaseGraphicsResources( aWindow );
+ }
+
Superclass::RemoveFromRender(theRenderer);
}
{
vtkProperty* aProperty = mySurfaceActor->GetProperty();
- if (theOn)
- {
- aProperty->SetAmbient(0.0);
- aProperty->SetDiffuse(1.0);
- }
- else
- {
- aProperty->SetAmbient(1.0);
- aProperty->SetDiffuse(0.0);
- }
+ if (theOn) {
+ aProperty->SetAmbient(0.0);
+ aProperty->SetDiffuse(1.0);
+ } else {
+ aProperty->SetAmbient(1.0);
+ aProperty->SetDiffuse(0.0);
+ }
}
//----------------------------------------------------------------------------
{
GetMatrix(myEdgeActor->GetUserMatrix());
GetMatrix(mySurfaceActor->GetUserMatrix());
+ GetMatrix(myPointsActor->GetUserMatrix());
using namespace SVTK::Representation;
- if( GetRepresentation() == Surfaceframe ){
+ switch ( GetRepresentation() ) {
+
+ case Surfaceframe:
mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
mySurfaceActor->RenderOpaqueGeometry(ren);
myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
myEdgeActor->RenderOpaqueGeometry(ren);
- }
- else{
+ break;
+
+ case Points:
+ myPointsActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
+ myPointsActor->RenderOpaqueGeometry(ren);
+ break;
+
+ default:
mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
mySurfaceActor->RenderOpaqueGeometry(ren);
}
+
return 1;
}
GetMatrix(mySurfaceActor->GetUserMatrix());
using namespace SVTK::Representation;
- if( GetRepresentation() == Surfaceframe ){
+ switch ( GetRepresentation() ) {
+
+ case Surfaceframe:
mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
mySurfaceActor->RenderTranslucentGeometry(ren);
myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
myEdgeActor->RenderTranslucentGeometry(ren);
- }
- else{
+ break;
+
+ case Points:
+ myPointsActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
+ myPointsActor->RenderTranslucentGeometry(ren);
+ break;
+
+ default:
mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
mySurfaceActor->RenderTranslucentGeometry(ren);
}
+
return 1;
}
VISU_ScalarMapAct
::GetMemorySize()
{
- return Superclass::GetMemorySize();
+ unsigned long int aSize = Superclass::GetMemorySize();
+
+ aSize += myPointsActor->GetMemorySize();
+
+ return aSize;
}
//----------------------------------------------------------------------------
#include "VISU_DataSetActor.h"
class VISU_ScalarBarActor;
+class VISU_PointsDeviceActor;
+
+//----------------------------------------------------------------------------
class VTKOCC_EXPORT VISU_ScalarMapAct : public VISU_DataSetActor
{
public:
bool myBarVisibility;
VISU_ScalarBarActor* myScalarBar;
+
+ VISU_PointsDeviceActor* myPointsActor;
SVTK_DeviceActor* mySurfaceActor;
SVTK_DeviceActor* myEdgeActor;
};
+//----------------------------------------------------------------------------
+
#endif
#include "VISU_Plot3DPL.hxx"
#include "VISU_ScalarBarActor.hxx"
+#include "VISU_OpenGLPointSpriteMapper.hxx"
+#include "VTKViewer_GeometryFilter.h"
+#include <vtkMaskPoints.h>
+
#include "VISU_Convertor.hxx"
#include "VISU_ConvertorUtils.hxx"
-typedef VISU_ScalarMapPL TPresent;
+typedef VISU_GaussPointsPL TPresent;
#include <vtkUnstructuredGrid.h>
#include <vtkDataSetMapper.h>
char aMainTexture[80];
strcpy( aMainTexture, getenv( "VISU_ROOT_DIR" ) );
- strcat( aMainTexture, "/share/salome/resources/visu/sprite_texture.vti" );
+ strcat( aMainTexture, "/share/salome/resources/visu/sprite_texture.bmp" );
char anAlphaTexture[80];
strcpy( anAlphaTexture, getenv( "VISU_ROOT_DIR" ) );
- strcat( anAlphaTexture, "/share/salome/resources/visu/sprite_alpha.vti" );
+ strcat( anAlphaTexture, "/share/salome/resources/visu/sprite_alpha.bmp" );
vtkSmartPointer<vtkImageData> aTextureValue =
VISU_GaussPointsPL::MakeTexture( aMainTexture, anAlphaTexture );
if(aValFieldIter == aValField.end()) return 0;
int aTimeStamp = aValFieldIter->first;
+ vtkActor* anActor = vtkActor::New();
VISU_ColoredPL* aPresent = NULL;
if(anEntity != VISU::NODE_ENTITY){
- continue;
aPresent = CreateColoredPL<TPresent>(aConvertor,
aMeshName,
anEntity,
aFieldName,
aTimeStamp);
+
+ anActor->SetMapper(aPresent->GetMapper());
}else{
+ continue;
aPresent = CreateColoredPL<TPresent>(aConvertor,
aMeshName,
anEntity,
aFieldName,
aTimeStamp);
- }
- vtkActor* anActor = vtkActor::New();
- anActor->SetMapper(aPresent->GetMapper());
+ VTKViewer_GeometryFilter* aGeometryFilter = VTKViewer_GeometryFilter::New();
+ aGeometryFilter->SetInput(aPresent->GetOutput());
+ aGeometryFilter->SetInside(true);
+
+ vtkMaskPoints* aMaskPoints = vtkMaskPoints::New();
+ aMaskPoints->SetInput(aGeometryFilter->GetOutput());
+ aMaskPoints->SetGenerateVertices(true);
+ aMaskPoints->SetOnRatio(1);
+
+ VISU_OpenGLPointSpriteMapper* aMapper = VISU_OpenGLPointSpriteMapper::New();
+ aMapper->SetAverageCellSize( VISU_DeformedShapePL::GetScaleFactor( aPresent->GetOutput() ) );
+
+ char aMainTexture[80];
+ strcpy( aMainTexture, getenv( "VISU_ROOT_DIR" ) );
+ strcat( aMainTexture, "/share/salome/resources/visu/sprite_texture.vti" );
+
+ char anAlphaTexture[80];
+ strcpy( anAlphaTexture, getenv( "VISU_ROOT_DIR" ) );
+ strcat( anAlphaTexture, "/share/salome/resources/visu/sprite_alpha.vti" );
+
+ vtkSmartPointer<vtkImageData> aTextureValue =
+ VISU_GaussPointsPL::MakeTexture( aMainTexture, anAlphaTexture );
+ aMapper->SetImageData( aTextureValue.GetPointer() );
+
+ //vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New();
+ aMapper->SetLookupTable(aPresent->GetMapperTable());
+ aMapper->SetUseLookupTableScalarRange(true);
+ aMapper->SetColorModeToMapScalars();
+ aMapper->SetScalarVisibility(true);
+
+ aMapper->SetInput(aMaskPoints->GetOutput());
+ aGeometryFilter->Delete();
+
+ anActor->SetMapper(aMapper);
+ aMapper->Delete();
+ }
VISU_ScalarBarActor * aScalarBar = VISU_ScalarBarActor::New();
aScalarBar->SetLookupTable(aPresent->GetBarTable());
glBindTexture( GL_TEXTURE_2D, this->PointSpriteTexture );
}
+
//-----------------------------------------------------------------------------
int ComputeHue( int r, int g, int b )
{
GLfloat vx, vy, vz;
};
+
//-----------------------------------------------------------------------------
-void VISU_OpenGLPointSpriteMapper::DrawPoints(vtkPoints *thePoints,
- vtkUnsignedCharArray *theColors,
- vtkCellArray *theCells,
- vtkActor* theActor)
+struct TColorFunctorBase
{
- //cout << "VISU_OpenGLPointSpriteMapper::DrawPoints" << endl;
+ virtual
+ void
+ get( TVertex& theVertex, vtkIdType thePointId, vtkIdType theCellId ) = 0;
+};
- //if( this->PrimitiveType == VISU_OpenGLPointSpriteMapper::OpenGLPoint )
- // glEnable( GL_POINT_SMOOTH );
- glPointSize( this->DefaultPointSize );
+//-----------------------------------------------------------------------------
+struct TPropertyColor : TColorFunctorBase
+{
+ vtkFloatingPointType myColor[3];
+ vtkFloatingPointType myHue;
- TVertex* aVertexArr = new TVertex[ this->TotalCells ];
+ TPropertyColor( vtkProperty *theProperty )
+ {
+ theProperty->GetColor( myColor );
+ int aRed = int( myColor[0] * 255 );
+ int aGreen = int( myColor[1] * 255 );
+ int aBlue = int( myColor[2] * 255 );
- vtkFloatingPointType* aPropertyColor = theActor->GetProperty()->GetColor();
- float aColor[3] = {aPropertyColor[0], aPropertyColor[1], aPropertyColor[2]};
+ myHue = ComputeHue( aRed, aGreen, aBlue );
+ }
- unsigned long i = 0;
- vtkIdType *pts = 0;
- vtkIdType npts = 0;
- for( theCells->InitTraversal(); theCells->GetNextCell( npts, pts ); i++ )
+ virtual
+ void
+ get( TVertex& theVertex, vtkIdType thePointId, vtkIdType theCellId )
{
- TVertex& aVertex = aVertexArr[i];
- vtkIdType aPointId = pts[0];
- vtkFloatingPointType* aCoords = thePoints->GetPoint( aPointId );
- aVertex.vx = aCoords[0];
- aVertex.vy = aCoords[1];
- aVertex.vz = aCoords[2];
-
- int aRed = 0, aGreen = 0, aBlue = 0;
- if( theColors && this->PointSpriteMode != 1 )
- {
- unsigned char *col = theColors->GetPointer(pts[0] << 2);
- aRed = int(col[0]);
- aGreen = int(col[1]);
- aBlue = int(col[2]);
-
- aColor[0] = aRed / 255.0;
- aColor[1] = aGreen / 255.0;
- aColor[2] = aBlue / 255.0;
- }
+ theVertex.r = myColor[0];
+ theVertex.g = myColor[1];
+ theVertex.b = myColor[2];
- aVertex.r = aColor[0];
- aVertex.g = aColor[1];
- aVertex.b = aColor[2];
- aVertex.hue = ComputeHue( aRed, aGreen, aBlue );
+ theVertex.hue = myHue;
}
+};
+
+
+//-----------------------------------------------------------------------------
+struct TColors2Color : TColorFunctorBase
+{
+ vtkUnsignedCharArray *myColors;
- GLuint aBufferObjectID = 0;
- vglGenBuffersARB( 1, &aBufferObjectID );
- vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID );
+ TColors2Color( vtkUnsignedCharArray *theColors ):
+ myColors( theColors )
+ {}
- int nArrayObjectSize = sizeof( TVertex ) * this->TotalCells;
- vglBufferDataARB( GL_ARRAY_BUFFER_ARB, nArrayObjectSize, aVertexArr, GL_STATIC_DRAW_ARB );
+ virtual
+ void
+ get( TVertex& theVertex, vtkIdType thePointId, vtkIdType theCellId )
+ {
+ vtkIdType aTupleId = GetTupleId( thePointId, theCellId );
+ unsigned char *aColor = myColors->GetPointer( aTupleId << 2 );
- delete [] aVertexArr;
+ theVertex.r = int( aColor[0] ) / 255.0;
+ theVertex.g = int( aColor[1] ) / 255.0;
+ theVertex.b = int( aColor[2] ) / 255.0;
- vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
- vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID );
+ theVertex.hue = ComputeHue( aColor[0], aColor[1], aColor[2] );
+ }
- glColorPointer( 4, GL_FLOAT, sizeof(TVertex), (void*)0 );
- glVertexPointer( 3, GL_FLOAT, sizeof(TVertex), (void*)(4*sizeof(GLfloat)) );
+ virtual
+ vtkIdType
+ GetTupleId( vtkIdType thePointId, vtkIdType theCellId ) = 0;
+};
- glEnableClientState( GL_VERTEX_ARRAY );
- glEnableClientState( GL_COLOR_ARRAY );
- glDrawArrays( GL_POINTS, 0, this->TotalCells );
+//-----------------------------------------------------------------------------
+struct TPointColors2Color : TColors2Color
+{
+ TPointColors2Color( vtkUnsignedCharArray *theColors ):
+ TColors2Color( theColors )
+ {}
+
+ virtual
+ vtkIdType
+ GetTupleId( vtkIdType thePointId, vtkIdType theCellId )
+ {
+ return thePointId;
+ }
+};
- glDisableClientState( GL_COLOR_ARRAY );
- glDisableClientState( GL_VERTEX_ARRAY );
- vglDeleteBuffersARB( 1, &aBufferObjectID );
+//-----------------------------------------------------------------------------
+struct TCellColors2Color : TColors2Color
+{
+ TCellColors2Color( vtkUnsignedCharArray *theColors ):
+ TColors2Color( theColors )
+ {}
- //if( this->PrimitiveType == VISU_OpenGLPointSpriteMapper::OpenGLPoint )
- // glDisable( GL_POINT_SMOOTH );
+ virtual
+ vtkIdType
+ GetTupleId( vtkIdType thePointId, vtkIdType theCellId )
+ {
+ return theCellId;
+ }
+};
+
+
+//-----------------------------------------------------------------------------
+template < class TCoordinates >
+void DrawPoints( TCoordinates *theStartPoints,
+ vtkCellArray *theCells,
+ TColorFunctorBase* theColorFunctor,
+ TVertex* theVertexArr,
+ vtkIdType &theCellId,
+ vtkIdType &theVertexId )
+{
+ vtkIdType *ptIds = theCells->GetPointer();
+ vtkIdType *endPtIds = ptIds + theCells->GetNumberOfConnectivityEntries();
+
+ while ( ptIds < endPtIds ) {
+ vtkIdType nPts = *ptIds;
+ ++ptIds;
+
+ while ( nPts > 0 ) {
+ TVertex& aVertex = theVertexArr[ theVertexId ];
+ vtkIdType aPointId = *ptIds;
+
+ TCoordinates *anOffsetPoints = theStartPoints + 3 * aPointId;
+ aVertex.vx = anOffsetPoints[0];
+ aVertex.vy = anOffsetPoints[1];
+ aVertex.vz = anOffsetPoints[2];
+
+ theColorFunctor->get( aVertex, aPointId, theCellId );
+
+ ++theVertexId;
+ ++ptIds;
+ --nPts;
+ }
+
+ ++theCellId;
+ }
}
+
+//-----------------------------------------------------------------------------
+template < class TCoordinates >
+void DrawCellsPoints( vtkPolyData *theInput,
+ vtkPoints* thePoints,
+ TColorFunctorBase* theColorFunctor,
+ TVertex* theVertexArr )
+{
+ vtkIdType aCellId = 0, aVertexId = 0;
+
+ TCoordinates *aStartPoints = (TCoordinates *) thePoints->GetVoidPointer(0);
+
+ if ( vtkCellArray* aCellArray = theInput->GetVerts() )
+ DrawPoints( aStartPoints, aCellArray, theColorFunctor, theVertexArr, aCellId, aVertexId );
+
+ if ( vtkCellArray* aCellArray = theInput->GetLines() )
+ DrawPoints( aStartPoints, aCellArray, theColorFunctor, theVertexArr, aCellId, aVertexId );
+
+ if ( vtkCellArray* aCellArray = theInput->GetPolys() )
+ DrawPoints( aStartPoints, aCellArray, theColorFunctor, theVertexArr, aCellId, aVertexId );
+
+ if ( vtkCellArray* aCellArray = theInput->GetStrips() )
+ DrawPoints( aStartPoints, aCellArray, theColorFunctor, theVertexArr, aCellId, aVertexId );
+}
+
+
//-----------------------------------------------------------------------------
int VISU_OpenGLPointSpriteMapper::Draw(vtkRenderer *theRenderer, vtkActor *theActor)
{
}
}
- // we need to know the total number of cells so that we can report progress
- this->TotalCells = input->GetVerts()->GetNumberOfCells();
+ {
+ vtkIdType aTotalConnectivitySize = 0;
+
+ if ( vtkCellArray* aCellArray = input->GetVerts() )
+ aTotalConnectivitySize += aCellArray->GetNumberOfConnectivityEntries() - aCellArray->GetNumberOfCells();
+
+ if ( vtkCellArray* aCellArray = input->GetLines() )
+ aTotalConnectivitySize += aCellArray->GetNumberOfConnectivityEntries() - aCellArray->GetNumberOfCells();
+
+ if ( vtkCellArray* aCellArray = input->GetPolys() )
+ aTotalConnectivitySize += aCellArray->GetNumberOfConnectivityEntries() - aCellArray->GetNumberOfCells();
+
+ if ( vtkCellArray* aCellArray = input->GetStrips() )
+ aTotalConnectivitySize += aCellArray->GetNumberOfConnectivityEntries() - aCellArray->GetNumberOfCells();
+
+ if ( aTotalConnectivitySize > 0 ) {
+ TVertex* aVertexArr = new TVertex[ aTotalConnectivitySize ];
+
+ vtkFloatingPointType aPropertyColor[3];
+ theActor->GetProperty()->GetColor( aPropertyColor );
+
+ glPointSize( this->DefaultPointSize );
+
+ {
+ TColorFunctorBase* aColorFunctor = NULL;
+ if( colors && this->PointSpriteMode != 1 ) {
+ if ( cellScalars )
+ aColorFunctor = new TCellColors2Color( colors );
+ else
+ aColorFunctor = new TPointColors2Color( colors );
+ } else {
+ aColorFunctor = new TPropertyColor( theActor->GetProperty() );
+ }
+ if ( points->GetDataType() == VTK_FLOAT )
+ ::DrawCellsPoints< float >( input, points, aColorFunctor, aVertexArr );
+ else
+ ::DrawCellsPoints< double >( input, points, aColorFunctor, aVertexArr );
+
+ delete aColorFunctor;
+ }
+
+ GLuint aBufferObjectID = 0;
+ vglGenBuffersARB( 1, &aBufferObjectID );
+ vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID );
+
+ int anArrayObjectSize = sizeof( TVertex ) * aTotalConnectivitySize;
+ vglBufferDataARB( GL_ARRAY_BUFFER_ARB, anArrayObjectSize, aVertexArr, GL_STATIC_DRAW_ARB );
+
+ delete [] aVertexArr;
+
+ vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
+ vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID );
+
+ glColorPointer( 4, GL_FLOAT, sizeof(TVertex), (void*)0 );
+ glVertexPointer( 3, GL_FLOAT, sizeof(TVertex), (void*)(4*sizeof(GLfloat)) );
+
+ glEnableClientState( GL_VERTEX_ARRAY );
+ glEnableClientState( GL_COLOR_ARRAY );
+
+ glDrawArrays( GL_POINTS, 0, aTotalConnectivitySize );
+
+ glDisableClientState( GL_COLOR_ARRAY );
+ glDisableClientState( GL_VERTEX_ARRAY );
+
+ vglDeleteBuffersARB( 1, &aBufferObjectID );
+ }
+
+ input->GetVerts()->GetNumberOfCells() +
+ input->GetLines()->GetNumberOfCells() +
+ input->GetPolys()->GetNumberOfCells() +
+ input->GetStrips()->GetNumberOfCells();
+
+
+
+ }
- this->DrawPoints(points, colors, input->GetVerts(), theActor);
this->UpdateProgress(1.0);
return noAbort;
VISU_OpenGLPointSpriteMapper();
~VISU_OpenGLPointSpriteMapper();
- //! Internal method of the Point Sprites drawing.
- void DrawPoints(vtkPoints *thePoints,
- vtkUnsignedCharArray *theColors,
- vtkCellArray *theCells,
- vtkActor* theActor);
-
//! Initializing OpenGL extensions.
bool InitExtensions();
bool theIsCopyInput)
{
// To customize vtkMapper::ShallowCopy ...
+ theTarget->SetLookupTable(theSource->GetLookupTable());
theTarget->SetScalarVisibility(theSource->GetScalarVisibility());
if(theIsCopyInput){
vtkFloatingPointType* aScalarRange = theSource->GetScalarRange();
#include "VISU_Result_i.hh"
#include "VISU_GaussPtsAct.h"
#include "VISU_GaussPointsPL.hxx"
-#include "VVTK_SegmentationCursorDlg.h"
+#include "VISU_GaussPtsDeviceActor.h"
#include "VISU_OpenGLPointSpriteMapper.hxx"
#include "VISU_ScalarBarCtrl.hxx"
#include "QtxDblSpinBox.h"
#include "QtxIntSpinBox.h"
-using namespace std;
-
-
-//----------------------------------------------------------------
-namespace VISU
-{
- inline
- QString
- Image2VTI(const QString& theImageFileName)
- {
- QFileInfo aFileInfo(theImageFileName);
- QString aFormat = aFileInfo.extension(FALSE);
-#ifdef WIN32
- QString aTmpDir = getenv( "TEMP" );
-#else
- QString aTmpDir = QString( "/tmp/" ) + getenv("USER");
-#endif
- QString aVTIName = aTmpDir + "-" + aFileInfo.baseName(TRUE) + ".vti";
- QString aCommand = QString( "VISU_img2vti " ) + aFormat + " " + theImageFileName + " " + aVTIName;
-
- if(system( aCommand.latin1() ) == 0)
- return aVTIName;
-
- return QString::null;
- }
-
- inline
- void
- RemoveFile(const QString& theFileName)
- {
- if( !theFileName.isNull() ){
-#ifndef WNT
- QString aCommand = QString( "rm -fr " ) + theFileName;
-#else:
- QString aCommand = QString( "del /F " ) + theFileName;
-#endif
- system( aCommand.latin1() );
- }
- }
-
-
- TTextureValue
- GetTexture(const QString& theMainTexture,
- const QString& theAlphaTexture)
- {
- typedef std::pair<std::string,std::string> TTextureKey;
- typedef std::map<TTextureKey,TTextureValue> TTextureMap;
-
- static TTextureMap aTextureMap;
-
- TTextureValue aTextureValue;
- TTextureKey aTextureKey(theMainTexture.latin1(),theAlphaTexture.latin1());
- TTextureMap::const_iterator anIter = aTextureMap.find(aTextureKey);
- if(anIter != aTextureMap.end()){
- aTextureValue = anIter->second;
- }else{
- QString aMainTextureVTI = Image2VTI(theMainTexture);
- QString anAlphaTextureVTI = Image2VTI(theAlphaTexture);
-
- if( !aMainTextureVTI.isNull() && !anAlphaTextureVTI.isNull() ){
- aTextureValue =
- VISU_GaussPointsPL::MakeTexture( aMainTextureVTI.latin1(),
- anAlphaTextureVTI.latin1());
-
- if( aTextureValue.GetPointer() )
- aTextureMap[aTextureKey] = aTextureValue;
- }
-
- RemoveFile(aMainTextureVTI);
- RemoveFile(anAlphaTextureVTI);
- }
-
- return aTextureValue;
- }
-}
-
-
//----------------------------------------------------------------
VVTK_SegmentationCursorDlg::VVTK_SegmentationCursorDlg( QWidget* parent, const char* name )
:QDialog( parent, name, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
#include "VVTK.h"
+#include "VISU_GaussPtsDeviceActor.h"
+
#include <qdialog.h>
#include <vtkObject.h>
class SVTK_RenderWindowInteractor;
-namespace VISU
-{
- typedef vtkSmartPointer<vtkImageData> TTextureValue;
-
- VVTK_EXPORT TTextureValue
- GetTexture(const QString& theMainTexture,
- const QString& theAlphaTexture);
-}
//! Segmentation Cursor Dialog.
/*!