-// SMESH OBJECT : interactive object for SMESH visualization
+// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
//
-// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+// SMESH OBJECT : interactive object for SMESH visualization
// File :
// Author :
// Module :
// $Header$
-
-
+//
#include "VISU_GaussPtsDeviceActor.h"
#include "VISU_GaussPointsPL.hxx"
#include "VTKViewer_Transform.h"
#include "VTKViewer_TransformFilter.h"
-#include "VTKViewer_PassThroughFilter.h"
+#include <SALOME_ExtractPolyDataGeometry.h>
#include <vtkObjectFactory.h>
#include <vtkPolyData.h>
#include <vtkTextProperty.h>
#include <vtkProperty.h>
#include <vtkTexture.h>
+#include <vtkPassThroughFilter.h>
+#include <vtkImageData.h>
+
+#include <QFileInfo>
#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.suffix();
+#ifdef WIN32
+ QString aTmpDir = getenv( "TEMP" );
+#else
+ QString aTmpDir = QString( "/tmp/" ) + getenv("USER");
+#endif
+ QString aVTIName = aTmpDir + "-" + aFileInfo.completeBaseName() + ".vti";
+ QString aCommand = QString( "VISU_img2vti " ) + aFormat + " " + theImageFileName.c_str() + " " + aVTIName;
+
+ if ( system( aCommand.toLatin1().data() ) == 0 )
+ return aVTIName.toLatin1().data();
+
+ 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.toLatin1().data() );
+ }
+ }
+
+
+ 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).c_str();
+ QString anAlphaTextureVTI = Image2VTI(theAlphaTexture).c_str();
+
+ if( !aMainTextureVTI.isNull() && !anAlphaTextureVTI.isNull() ){
+ aTextureValue =
+ VISU_GaussPointsPL::MakeTexture( aMainTextureVTI.toLatin1().data(),
+ anAlphaTextureVTI.toLatin1().data() );
+
+ if( aTextureValue.GetPointer() )
+ aTextureMap[aTextureKey] = aTextureValue;
+ }
+
+ RemoveFile(aMainTextureVTI.toLatin1().data());
+ RemoveFile(anAlphaTextureVTI.toLatin1().data());
+ }
+
+ return aTextureValue;
+ }
+}
//----------------------------------------------------------------
-vtkStandardNewMacro(VISU_GaussPtsDeviceActor);
+vtkStandardNewMacro(VISU_GaussDeviceActorBase);
-VISU_GaussPtsDeviceActor
-::VISU_GaussPtsDeviceActor():
- myGeomFilter(VTKViewer_GeometryFilter::New()),
- myTransformFilter(VTKViewer_TransformFilter::New())
+VISU_GaussDeviceActorBase
+::VISU_GaussDeviceActorBase():
+ myTransformFilter(VTKViewer_TransformFilter::New()),
+ myPolyDataExtractor(0)
{
- if(MYDEBUG) MESSAGE("VISU_GaussPtsDeviceActor - "<<this);
+ if(MYDEBUG) MESSAGE("VISU_GaussDeviceActorBase - "<<this);
- myGeomFilter->Delete();
myTransformFilter->Delete();
for(int i = 0; i < 3; i++){
- PPassThroughFilter aFilter(VTKViewer_PassThroughFilter::New());
+ PPassThroughFilter aFilter(vtkPassThroughFilter::New());
myPassFilter.push_back(aFilter);
aFilter->Delete();
}
}
-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_GaussDeviceActorBase
+::SetTransform(VTKViewer_Transform* theTransform)
+{
+ myTransformFilter->SetTransform(theTransform);
+}
+
+//----------------------------------------------------------------
+void
+VISU_GaussDeviceActorBase
+::SetPointSpriteMapper(VISU_OpenGLPointSpriteMapper* theMapper)
+{
+ vtkPolyData* aDataSet = theMapper->GetInput();
+ myMapper = theMapper;
+
+ int anId = 0;
+ if (myPolyDataExtractor) {
+ myPolyDataExtractor->SetInput(aDataSet);
+ myPassFilter[ anId ]->SetInput( myPolyDataExtractor->GetOutput() );
+ } else {
+ 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_GaussDeviceActorBase
+::DoMapperShallowCopy( vtkMapper* theMapper,
+ bool theIsCopyInput )
+{
+ VISU::CopyMapper( GetMapper(), theMapper, theIsCopyInput );
+}
+
+VISU_OpenGLPointSpriteMapper*
+VISU_GaussDeviceActorBase
+::GetPointSpriteMapper()
+{
+ return myMapper.GetPointer();
+}
+
+//----------------------------------------------------------------------------
+unsigned long int
+VISU_GaussDeviceActorBase
+::GetMemorySize()
+{
+ vtkDataSet* aDataSet = GetMapper()->GetInput();
+ return aDataSet->GetActualMemorySize() * 1024;
+}
+
+
+
+//----------------------------------------------------------------
+vtkStandardNewMacro(VISU_GaussPtsDeviceActor);
+
+
+VISU_GaussPtsDeviceActor
+::VISU_GaussPtsDeviceActor()
+{}
+
+
+VISU_GaussPtsDeviceActor
+::~VISU_GaussPtsDeviceActor()
+{}
+
+
+//----------------------------------------------------------------------------
+void
VISU_GaussPtsDeviceActor
::AddToRender(vtkRenderer* theRenderer)
{
theRenderer->RemoveActor(this);
}
+
+//----------------------------------------------------------------------------
void
VISU_GaussPtsDeviceActor
-::SetTransform(VTKViewer_Transform* theTransform)
+::SetPipeLine(VISU_GaussPointsPL* thePipeLine)
{
- myTransformFilter->SetTransform(theTransform);
+ SetPointSpriteMapper( thePipeLine->GetPointSpriteMapper() );
+
+ myPipeLine = thePipeLine;
}
-VISU_OpenGLPointSpriteMapper*
+VISU_GaussPointsPL*
VISU_GaussPtsDeviceActor
-::GetPSMapper()
+::GetPipeLine()
+{
+ return myPipeLine.GetPointer();
+}
+
+void
+VISU_GaussPtsDeviceActor
+::ShallowCopyPL(VISU_GaussPointsPL* thePipeLine)
{
- return myMapper.GetPointer();
+ myPipeLine->ShallowCopy(thePipeLine, true);
}
+
+//----------------------------------------------------------------------------
int
VISU_GaussPtsDeviceActor
::GetPickable()
if(Superclass::GetPickable()){
if(vtkMapper* aMapper = GetMapper()){
if(vtkDataSet* aDataSet= aMapper->GetInput()){
- aDataSet->Update();
- return aDataSet->GetNumberOfCells() > 0;
+ aDataSet->Update();
+ return aDataSet->GetNumberOfCells() > 0;
}
}
}
//----------------------------------------------------------------------------
-void
+unsigned long int
VISU_GaussPtsDeviceActor
-::SetPipeLine(VISU_GaussPointsPL* thePipeLine)
+::GetMemorySize()
{
- myPipeLine = thePipeLine;
- myMapper = thePipeLine->GetPSMapper();
- vtkPolyData* aDataSet = myMapper->GetInput();
+ unsigned long int aSize = Superclass::GetMemorySize();
- 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() );
-}
+ aSize += GetPipeLine()->GetMemorySize();
-VISU_GaussPointsPL*
-VISU_GaussPtsDeviceActor
-::GetPipeLine()
-{
- return myPipeLine.GetPointer();
+ return aSize;
}
-void
-VISU_GaussPtsDeviceActor
-::ShallowCopyPL(VISU_GaussPointsPL* thePipeLine)
-{
- myPipeLine->ShallowCopy(thePipeLine);
-}
//============================================================================
void
VISU_CursorPyramid
::SetPreferences(vtkFloatingPointType theHeight,
- vtkFloatingPointType theCursorSize)
+ vtkFloatingPointType theCursorSize)
{
Init(theHeight, theCursorSize, myRadius, myMagnification, myClamp, GetPosition(), GetProperty()->GetColor());
}
mySources[5]->SetCenter(0.0, 0.0, -aDisplacement);
}
-
-//----------------------------------------------------------------------------
-#include <vtkViewport.h>
-#include <vtkWindow.h>
-#include <vtkProp.h>
-#include <vtkPolyData.h>
-#include <vtkPolyDataMapper2D.h>
-#include <vtkActor2D.h>
-#include <vtkTimeStamp.h>
-#include <vtkTextProperty.h>
-#include <vtkTextActor.h>
-#include <vtkTextMapper.h>
-#include <vtkPoints.h>
-#include <vtkCellArray.h>
-#include <vtkProperty2D.h>
-//==================================================================
-vtkCxxRevisionMacro(VISU_FramedTextActor, "$Revision$");
-vtkStandardNewMacro(VISU_FramedTextActor);
-
-//==================================================================
-// function : VISU_FramedTextActor
-// purpose :
-//==================================================================
-VISU_FramedTextActor::VISU_FramedTextActor()
-{
- PositionCoordinate->SetCoordinateSystemToNormalizedViewport();
-
- myTransparency=0.;
- myBar = vtkPolyData::New();
- myBarMapper = vtkPolyDataMapper2D::New();
- myBarMapper->SetInput(myBar);
- myBarActor = vtkActor2D::New();
- myBarActor->SetMapper(myBarMapper);
- myBarActor->GetProperty()->SetOpacity(1.-myTransparency);
- myBarActor->GetProperty()->SetColor(.5, .5, .5);
- //
- myTextProperty = vtkTextProperty::New();
- myTextProperty->SetFontSize(12);
- myTextProperty->SetBold(0);
- myTextProperty->SetItalic(0);
- myTextProperty->SetShadow(1);
- myTextProperty->SetFontFamilyToArial();
- //
- myTextMapper=vtkTextMapper::New();
- myTextMapper->SetInput("some text");
- myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty);
- myTextActor=vtkActor2D::New();
- myTextActor->SetMapper(myTextMapper);
- //
- myBarActor->SetVisibility(1);
- myTextActor->SetVisibility(1);
- myBarActor->SetPickable(0);
- myTextActor->SetPickable(0);
- //----------------------------------------------------------
- myModePosition=0;// 0 -centered below the point
- // 1 -top left corner of the 3D view window
- //
- for(int i=0; i<4; i++) {
- myWorldPoint[i] = 0.;
- }
- myDistance=10.;
- //
-}
-//==================================================================
-// function : ~
-// purpose :
-//==================================================================
-VISU_FramedTextActor::~VISU_FramedTextActor()
-{
- myTextActor->Delete();
- myTextMapper->Delete();
- myTextProperty->Delete();
- myBarActor->Delete();
- myBarMapper->Delete();
- myBar->Delete();
-}
-//==================================================================
-// function : SetVisibility
-// purpose :
-//==================================================================
-void VISU_FramedTextActor::SetVisibility (int theVisibility)
-{
- myBarActor->SetVisibility(theVisibility);
- myTextActor->SetVisibility(theVisibility);
-}
-//==================================================================
-// function : GetVisibility
-// purpose :
-//==================================================================
-int VISU_FramedTextActor::GetVisibility()
-{
- return myBarActor->GetVisibility();
-}
-//==================================================================
-// function : SetPickable
-// purpose :
-//==================================================================
-void VISU_FramedTextActor::SetPickable (int thePickability)
-{
- myBarActor->SetPickable(thePickability);
- myTextActor->SetPickable(thePickability);
-}
-//==================================================================
-// function : GetPickable
-// purpose :
-//==================================================================
-int VISU_FramedTextActor::GetPickable()
-{
- return myBarActor->GetPickable();
-}
-//==================================================================
-// function : SetTransparency
-// purpose :
-//==================================================================
-void VISU_FramedTextActor::SetTransparency(const vtkFloatingPointType theTransparency)
-{
- if (theTransparency>=0. && theTransparency<=1.){
- myTransparency=theTransparency;
- myBarActor->GetProperty()->SetOpacity(1.-myTransparency);
- Modified();
- }
-}
-//==================================================================
-// function : GetTransparency
-// purpose :
-//==================================================================
-vtkFloatingPointType VISU_FramedTextActor::GetTransparency()const
-{
- return myTransparency;
-}
-//==================================================================
-// function : SetText
-// purpose :
-//==================================================================
-void VISU_FramedTextActor::SetText(const char* theText)
-{
- myTextMapper->SetInput(theText);
- Modified();
-}
-//==================================================================
-// function : GetText
-// purpose :
-//==================================================================
-char* VISU_FramedTextActor::GetText()
-{
- return myTextMapper->GetInput();
-}
-//==================================================================
-// function : SetModePosition
-// purpose :
-//==================================================================
-void VISU_FramedTextActor::SetModePosition(const int theMode)
-{
- myModePosition=theMode;
- Modified();
-}
-//==================================================================
-// function : GetModePosition
-// purpose :
-//==================================================================
-int VISU_FramedTextActor::GetModePosition()const
-{
- return myModePosition;
-}
-//==================================================================
-// function : SetWorldPoint
-// purpose :
-//==================================================================
-void VISU_FramedTextActor::SetWorldPoint(const vtkFloatingPointType theWorldPoint[4])
-{
- for(int i = 0; i<4; ++i) {
- myWorldPoint[i] = theWorldPoint[i];
- }
- Modified();
-}
-//==================================================================
-// function : GetWorldPoint
-// purpose :
-//==================================================================
-const vtkFloatingPointType* VISU_FramedTextActor::GetWorldPoint()const
-{
- return myWorldPoint;
-}
-//==================================================================
-// function : SetDistance
-// purpose :
-//==================================================================
-void VISU_FramedTextActor::SetDistance(const vtkFloatingPointType theDistance)
-{
- myDistance=theDistance;
-}
-//==================================================================
-// function : GetDistance
-// purpose :
-//==================================================================
-vtkFloatingPointType VISU_FramedTextActor::GetDistance()const
-{
- return myDistance;
-}
-//==================================================================
-// function : ReleaseGraphicsResources
-// purpose :
-//==================================================================
-void VISU_FramedTextActor::ReleaseGraphicsResources(vtkWindow *win)
-{
- myTextActor->ReleaseGraphicsResources(win);
- myBarActor->ReleaseGraphicsResources(win);
-}
-//==================================================================
-// function : RenderOverlay
-// purpose :
-//==================================================================
-int VISU_FramedTextActor::RenderOverlay(vtkViewport *viewport)
-{
- int renderedSomething = 0;
- myBarActor->RenderOverlay(viewport);
- renderedSomething +=myTextActor->RenderOverlay(viewport);
- return renderedSomething;
-}
-//==================================================================
-// function : RenderOpaqueGeometry
-// purpose :
-//==================================================================
-int
-VISU_FramedTextActor
-::RenderOpaqueGeometry(vtkViewport *theViewport)
-{
- int anIsRenderedSomething = 0;
- int* aViewportSize = theViewport->GetSize();
- if(aViewportSize[0] == 1 || aViewportSize[1] == 1)
- return anIsRenderedSomething;
-
- myBar->Initialize();
-
- int aNbPoints = 4;
- vtkPoints *aPoints = vtkPoints::New();
- aPoints->SetNumberOfPoints(aNbPoints);
- myBar->SetPoints(aPoints);
- aPoints->Delete();
-
- vtkCellArray *aPolys = vtkCellArray::New();
- aPolys->Allocate(aPolys->EstimateSize(1,4));
- vtkIdType aPointsIds[4] = {0, 1, 3, 2};
- aPolys->InsertNextCell(4,aPointsIds);
- myBar->SetPolys(aPolys);
- aPolys->Delete();
-
- int aTextSize[2];
- myTextMapper->GetSize(theViewport, aTextSize);
- int aBarWidth = aTextSize[0];
- int aBarHeight = aTextSize[1];
-
- if (myModePosition==0) {
- theViewport->SetWorldPoint(myWorldPoint);
- theViewport->WorldToDisplay();
-
- vtkFloatingPointType aSelectionPoint[3];
- theViewport->GetDisplayPoint(aSelectionPoint);
- vtkFloatingPointType u = aSelectionPoint[0];
- vtkFloatingPointType v = aSelectionPoint[1] - myDistance;
- theViewport->ViewportToNormalizedViewport(u, v);
- PositionCoordinate->SetValue(u, v);
- //
- myTextProperty->SetJustificationToCentered();
- myTextProperty->SetVerticalJustificationToTop();
- //
- aBarWidth /= 2;
- aPoints->SetPoint(0, -aBarWidth, 0.0, 0.0);
- aPoints->SetPoint(1, -aBarWidth, -aBarHeight, 0.0);
- aPoints->SetPoint(2, aBarWidth, 0.0, 0.0);
- aPoints->SetPoint(3, aBarWidth, -aBarHeight, 0.0);
- }
- else {//if (myModePosition==1) {
- PositionCoordinate->SetValue(0.0, 1.0);
- myTextProperty->SetJustificationToLeft();
- myTextProperty->SetVerticalJustificationToTop();
- //
- aPoints->SetPoint(0, 0.0, 0.0, 0.0);
- aPoints->SetPoint(1, 0.0, -aBarHeight, 0.0);
- aPoints->SetPoint(2, aBarWidth, 0.0, 0.0);
- aPoints->SetPoint(3, aBarWidth, -aBarHeight, 0.0);
- }
- //
- myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty);
- myBarActor ->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate);
- myTextActor->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate);
- //
- myBuildTime.Modified();
- //
- return anIsRenderedSomething;
-}