From: ouv Date: Fri, 9 Oct 2009 12:27:36 +0000 (+0000) Subject: Bug IPAL21328 - Values Labeling are not shown where Translated Presentation is, but... X-Git-Tag: V5_1_3rc1~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ab482f6ad2084c754483c1b1ff187d46ede6414f;p=modules%2Fvisu.git Bug IPAL21328 - Values Labeling are not shown where Translated Presentation is, but remain on initial place. --- diff --git a/src/OBJECT/Makefile.am b/src/OBJECT/Makefile.am index 25572620..7ae989b8 100644 --- a/src/OBJECT/Makefile.am +++ b/src/OBJECT/Makefile.am @@ -44,6 +44,7 @@ salomeinclude_HEADERS = \ VISU_PointMap3dActor.h \ VISU_ActorBase.h \ VISU_IsoSurfActor.h \ + VISU_SelectVisiblePoints.h \ VISU_OBJECT.h dist_libVisuObject_la_SOURCES = \ @@ -58,7 +59,8 @@ dist_libVisuObject_la_SOURCES = \ VISU_VectorsAct.cxx \ VISU_PointMap3dActor.cxx \ VISU_ActorBase.cxx \ - VISU_IsoSurfActor.cxx + VISU_IsoSurfActor.cxx \ + VISU_SelectVisiblePoints.cxx libVisuObject_la_CPPFLAGS= \ $(QT_INCLUDES) \ diff --git a/src/OBJECT/VISU_Actor.cxx b/src/OBJECT/VISU_Actor.cxx index c6087f4c..959fce3d 100644 --- a/src/OBJECT/VISU_Actor.cxx +++ b/src/OBJECT/VISU_Actor.cxx @@ -29,6 +29,7 @@ #include "VISU_ActorFactory.h" #include "VISU_PickingSettings.h" #include "VISU_GaussPtsDeviceActor.h" +#include "VISU_SelectVisiblePoints.h" #include "VISU_PipeLine.hxx" @@ -54,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -67,7 +69,6 @@ #include #include #include -#include #include #include @@ -165,7 +166,7 @@ VISU_Actor myValMaskPoints->SetInput(myValCellCenters->GetOutput()); myValMaskPoints->SetOnRatio(1); - myValSelectVisiblePoints = vtkSelectVisiblePoints::New(); + myValSelectVisiblePoints = VISU_SelectVisiblePoints::New(); myValSelectVisiblePoints->SetInput(myValMaskPoints->GetOutput()); myValSelectVisiblePoints->SelectInvisibleOff(); myValSelectVisiblePoints->SetTolerance(0.1); @@ -201,6 +202,11 @@ VISU_Actor myValLabels->SetMapper(myValLabeledDataMapper); myValLabels->GetProperty()->SetColor(0,1,0); myValLabels->SetVisibility( myIsValLabeled ); + + // to allow modification of the reference coordinate in redefined SetPosition() methods + vtkCoordinate* aValLabelsCoordinate = vtkCoordinate::New(); + myValLabels->GetPositionCoordinate()->SetReferenceCoordinate( aValLabelsCoordinate ); + aValLabelsCoordinate->Delete(); } //---------------------------------------------------------------------------- @@ -579,6 +585,29 @@ VISU_Actor { return GetFactory()->GetActiveState(); } + +//---------------------------------------------------------------------------- +void +VISU_Actor +::SetPosition( double thePosition[3] ) +{ + Superclass::SetPosition( thePosition ); + if( vtkCoordinate* aCoord = myValLabels->GetPositionCoordinate()->GetReferenceCoordinate() ) + aCoord->SetValue( thePosition ); + myValSelectVisiblePoints->SetOffset( thePosition ); +} + +//---------------------------------------------------------------------------- +void +VISU_Actor +::SetPosition( double theX, double theY, double theZ ) +{ + Superclass::SetPosition( theX, theY, theZ ); + if( vtkCoordinate* aCoord = myValLabels->GetPositionCoordinate()->GetReferenceCoordinate() ) + aCoord->SetValue( theX, theY, theZ ); + myValSelectVisiblePoints->SetOffset( theX, theY, theZ ); +} + //---------------------------------------------------------------------------- void VISU_Actor diff --git a/src/OBJECT/VISU_Actor.h b/src/OBJECT/VISU_Actor.h index f29a20f8..bb69e585 100644 --- a/src/OBJECT/VISU_Actor.h +++ b/src/OBJECT/VISU_Actor.h @@ -51,13 +51,14 @@ class vtkImplicitFunctionCollection; class vtkFeatureEdges; class vtkTextProperty; class vtkCellCenters; -class vtkSelectVisiblePoints; class vtkLabeledDataMapper; class vtkMaskPoints; class vtkActor2D; class VTKViewer_FramedTextActor; +class VISU_SelectVisiblePoints; + #if !defined(VTK_XVERSION) #define VTK_XVERSION (VTK_MAJOR_VERSION<<16)+(VTK_MINOR_VERSION<<8)+(VTK_BUILD_VERSION) #endif @@ -115,6 +116,14 @@ class VISU_OBJECT_EXPORT VISU_Actor : public VISU_ActorBase bool ShouldBeDisplayed(); + virtual + void + SetPosition( double thePosition[3] ); + + virtual + void + SetPosition( double theX, double theY, double theZ ); + //---------------------------------------------------------------------------- virtual VISU_PipeLine* @@ -408,7 +417,7 @@ class VISU_OBJECT_EXPORT VISU_Actor : public VISU_ActorBase vtkMaskPoints* myValMaskPoints; vtkCellCenters* myValCellCenters; vtkLabeledDataMapper* myValLabeledDataMapper; - vtkSelectVisiblePoints* myValSelectVisiblePoints; + VISU_SelectVisiblePoints* myValSelectVisiblePoints; }; #endif //VISU_ACTOR_H diff --git a/src/OBJECT/VISU_SelectVisiblePoints.cxx b/src/OBJECT/VISU_SelectVisiblePoints.cxx new file mode 100644 index 00000000..1f91cae1 --- /dev/null +++ b/src/OBJECT/VISU_SelectVisiblePoints.cxx @@ -0,0 +1,229 @@ +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// +// VISU OBJECT : interactive object for VISU entities implementation +// File : VISU_SelectVisiblePoints.h +// Author : Oleg UVAROV +// Module : VISU + +#include "VISU_SelectVisiblePoints.h" + +#include "vtkCamera.h" +#include "vtkCellArray.h" +#include "vtkDataSet.h" +#include "vtkMatrix4x4.h" +#include "vtkInformation.h" +#include "vtkInformationVector.h" +#include "vtkObjectFactory.h" +#include "vtkPointData.h" +#include "vtkPoints.h" +#include "vtkPolyData.h" +#include "vtkRenderWindow.h" +#include "vtkRenderer.h" + +vtkStandardNewMacro(VISU_SelectVisiblePoints); + +// Instantiate object with no renderer; window selection turned off; +// tolerance set to 0.01; and select invisible off. +VISU_SelectVisiblePoints::VISU_SelectVisiblePoints() +{ + this->Offset[0] = this->Offset[1] = this->Offset[2] = 0.0; +} + +VISU_SelectVisiblePoints::~VISU_SelectVisiblePoints() +{ +} + +int VISU_SelectVisiblePoints::RequestData( + vtkInformation *vtkNotUsed(request), + vtkInformationVector **inputVector, + vtkInformationVector *outputVector) +{ + // get the info objects + vtkInformation *inInfo = inputVector[0]->GetInformationObject(0); + vtkInformation *outInfo = outputVector->GetInformationObject(0); + + // get the input and ouptut + vtkDataSet *input = vtkDataSet::SafeDownCast( + inInfo->Get(vtkDataObject::DATA_OBJECT())); + vtkPolyData *output = vtkPolyData::SafeDownCast( + outInfo->Get(vtkDataObject::DATA_OBJECT())); + + vtkIdType ptId, cellId; + int visible; + vtkPoints *outPts; + vtkCellArray *outputVertices; + vtkPointData *inPD=input->GetPointData(); + vtkPointData *outPD=output->GetPointData(); + vtkIdType numPts=input->GetNumberOfPoints(); + double x[4], xTrans[4]; + double dx[3], z; + int selection[4]; + + if ( this->Renderer == NULL ) + { + vtkErrorMacro(<<"Renderer must be set"); + return 0; + } + + if ( numPts < 1 ) + { + return 0; + } + + outPts = vtkPoints::New(); + outPts->Allocate(numPts/2+1); + outPD->CopyAllocate(inPD); + + outputVertices = vtkCellArray::New(); + output->SetVerts(outputVertices); + outputVertices->Delete(); + + int *size = this->Renderer->GetRenderWindow()->GetSize(); + + // specify a selection window to avoid querying + if ( this->SelectionWindow ) + { + for (int i=0; i<4; i++) + { + selection[i] = this->Selection[i]; + } + } + else + { + selection[0] = selection[2] = 0; + selection[1] = size[0] - 1; + selection[3] = size[1] - 1; + } + + // Grab the composite perspective transform. This matrix is used to convert + // each point to view coordinates. vtkRenderer provides a WorldToView() + // method but it computes the composite perspective transform each time + // WorldToView() is called. This is expensive, so we get the matrix once + // and handle the transformation ourselves. + vtkMatrix4x4 *matrix = vtkMatrix4x4::New(); + double view[4]; + matrix->DeepCopy(this->Renderer->GetActiveCamera()-> + GetCompositePerspectiveTransformMatrix( + this->Renderer->GetTiledAspectRatio(),0,1)); + + // If we have more than a few query points, we grab the z-buffer for the + // selection region all at once and probe the resulting array. When we + // have just a few points, we perform individual z-buffer queries. + const int SimpleQueryLimit = 25; + float *zPtr = NULL; + if (numPts > SimpleQueryLimit) + { + zPtr = this->Renderer->GetRenderWindow()-> + GetZbufferData(selection[0], selection[2], selection[1], selection[3]); + } + + int abort=0; + vtkIdType progressInterval=numPts/20+1; + x[3] = 1.0; + for (cellId=(-1), ptId=0; ptId < numPts && !abort; ptId++) + { + // perform conversion + input->GetPoint(ptId,x); + + // take into account translation offset (this is the only difference + // between this class and native vtkSelectVisiblePoints class) + xTrans[0] = x[0] + this->Offset[0]; + xTrans[1] = x[1] + this->Offset[1]; + xTrans[2] = x[2] + this->Offset[2]; + xTrans[3] = 1.0; + + matrix->MultiplyPoint(xTrans, view); + if (view[3] == 0.0) + { + continue; + } + this->Renderer->SetViewPoint(view[0]/view[3], view[1]/view[3], + view[2]/view[3]); + this->Renderer->ViewToDisplay(); + this->Renderer->GetDisplayPoint(dx); + visible = 0; + + if ( ! (ptId % progressInterval) ) + { + this->UpdateProgress((double)ptId/numPts); + abort = this->GetAbortExecute(); + } + + // check whether visible and in selection window + if ( dx[0] >= selection[0] && dx[0] <= selection[1] && + dx[1] >= selection[2] && dx[1] <= selection[3] ) + { + if (numPts > SimpleQueryLimit) + { + // Access the value from the captured zbuffer. Note, we only + // captured a portion of the zbuffer, so we need to offset dx by + // the selection window. + z = zPtr[(int)dx[0] - selection[0] + + ((int)dx[1] - selection[2]) + *(selection[1] - selection[0] + 1)]; + } + else + { + z = this->Renderer->GetZ(static_cast(dx[0]), + static_cast(dx[1])); + } + if( dx[2] < (z + this->Tolerance) ) + { + visible = 1; + } + } + + if ( (visible && !this->SelectInvisible) || + (!visible && this->SelectInvisible) ) + { + cellId = outPts->InsertNextPoint(x); + output->InsertNextCell(VTK_VERTEX, 1, &cellId); + outPD->CopyData(inPD,ptId,cellId); + } + }//for all points + + output->SetPoints(outPts); + outPts->Delete(); + output->Squeeze(); + + matrix->Delete(); + + if (zPtr) + { + delete [] zPtr; + } + + vtkDebugMacro(<<"Selected " << cellId + 1 << " out of " + << numPts << " original points"); + + return 1; +} + +void VISU_SelectVisiblePoints::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os,indent); + + os << indent << "Offset: (" + << this->Offset[0] << ", " + << this->Offset[1] << ", " + << this->Offset[2] << ")\n"; +} diff --git a/src/OBJECT/VISU_SelectVisiblePoints.h b/src/OBJECT/VISU_SelectVisiblePoints.h new file mode 100644 index 00000000..d112326b --- /dev/null +++ b/src/OBJECT/VISU_SelectVisiblePoints.h @@ -0,0 +1,65 @@ +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// +// VISU OBJECT : interactive object for VISU entities implementation +// File : VISU_SelectVisiblePoints.h +// Author : Oleg UVAROV +// Module : VISU + +#ifndef VISU_SelectVisiblePoints_HeaderFile +#define VISU_SelectVisiblePoints_HeaderFile + +#include "VISU_OBJECT.h" + +#include "vtkSelectVisiblePoints.h" + +class vtkRenderer; + +class VISU_OBJECT_EXPORT VISU_SelectVisiblePoints : public vtkSelectVisiblePoints +{ +public: + vtkTypeMacro(VISU_SelectVisiblePoints,vtkSelectVisiblePoints); + void PrintSelf(ostream& os, vtkIndent indent); + + // Description: + // Instantiate object with no renderer; window selection turned off; + // tolerance set to 0.01; and select invisible off. + static VISU_SelectVisiblePoints *New(); + + // Description: + // Set/Get a translation offset for input points. + vtkSetVector3Macro(Offset,double); + vtkGetVectorMacro(Offset,double,4); + +protected: + VISU_SelectVisiblePoints(); + ~VISU_SelectVisiblePoints(); + + virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); + + double Offset[3]; + +private: + VISU_SelectVisiblePoints(const VISU_SelectVisiblePoints&); // Not implemented. + void operator=(const VISU_SelectVisiblePoints&); // Not implemented. +}; + +#endif