Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "SMESHGUI_MeshEditPreview.h"
00029
00030 #include "SMESHGUI_VTKUtils.h"
00031
00032 #include <SMESH_Actor.h>
00033 #include <SMESH_ActorUtils.h>
00034
00035
00036 #include <VTKViewer_CellLocationsArray.h>
00037 #include <SVTK_ViewWindow.h>
00038
00039
00040 #include <vtkPoints.h>
00041 #include <vtkIdList.h>
00042 #include <vtkCellArray.h>
00043 #include <vtkUnsignedCharArray.h>
00044 #include <vtkUnstructuredGrid.h>
00045 #include <vtkUnstructuredGridWriter.h>
00046 #include <vtkDataSetMapper.h>
00047 #include <vtkProperty.h>
00048
00049
00050 #include <QColor>
00051
00052
00053 #include <SALOMEconfig.h>
00054 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00055
00056
00060
00061
00062 SMESHGUI_MeshEditPreview::SMESHGUI_MeshEditPreview(SVTK_ViewWindow* theViewWindow):
00063 myViewWindow(theViewWindow)
00064 {
00065 myGrid = vtkUnstructuredGrid::New();
00066
00067
00068 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
00069 aMapper->SetInput( myGrid );
00070
00071 myPreviewActor = SALOME_Actor::New();
00072 myPreviewActor->SetInfinitive(true);
00073 myPreviewActor->VisibilityOn();
00074 myPreviewActor->PickableOff();
00075
00076 vtkFloatingPointType anRGB[3];
00077 SMESH::GetColor( "SMESH", "selection_element_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
00078 SetColor( anRGB[0], anRGB[1], anRGB[2] );
00079
00080 myPreviewActor->SetMapper( aMapper );
00081 aMapper->Delete();
00082
00083 myViewWindow->AddActor(myPreviewActor);
00084
00085 }
00086
00087
00091
00092
00093 SMESHGUI_MeshEditPreview::~SMESHGUI_MeshEditPreview()
00094 {
00095 myGrid->Delete();
00096
00097 myViewWindow->RemoveActor(myPreviewActor);
00098 myPreviewActor->Delete();
00099
00100 }
00101
00102
00106
00107
00108 vtkIdType getCellType( const SMDSAbs_ElementType theType,
00109 const bool thePoly,
00110 const int theNbNodes )
00111 {
00112 switch( theType )
00113 {
00114 case SMDSAbs_Node: return VTK_VERTEX;
00115 case SMDSAbs_Edge:
00116 if( theNbNodes == 2 ) return VTK_LINE;
00117 else if ( theNbNodes == 3 ) return VTK_QUADRATIC_EDGE;
00118 else return VTK_EMPTY_CELL;
00119
00120 case SMDSAbs_Face :
00121 if (thePoly && theNbNodes>2 ) return VTK_POLYGON;
00122 else if ( theNbNodes == 3 ) return VTK_TRIANGLE;
00123 else if ( theNbNodes == 4 ) return VTK_QUAD;
00124 else if ( theNbNodes == 6 ) return VTK_QUADRATIC_TRIANGLE;
00125 else if ( theNbNodes == 8 ) return VTK_QUADRATIC_QUAD;
00126 else return VTK_EMPTY_CELL;
00127
00128 case SMDSAbs_Volume:
00129 if (thePoly && theNbNodes>3 ) return VTK_CONVEX_POINT_SET;
00130 else if ( theNbNodes == 4 ) return VTK_TETRA;
00131 else if ( theNbNodes == 5 ) return VTK_PYRAMID;
00132 else if ( theNbNodes == 6 ) return VTK_WEDGE;
00133 else if ( theNbNodes == 8 ) return VTK_HEXAHEDRON;
00134 else if ( theNbNodes == 10 ) {
00135 return VTK_QUADRATIC_TETRA;
00136 }
00137 else if ( theNbNodes == 20 ) {
00138 return VTK_QUADRATIC_HEXAHEDRON;
00139 }
00140 else if ( theNbNodes==15 ) {
00141 return VTK_QUADRATIC_WEDGE;
00142 }
00143 else if ( theNbNodes==13 ) {
00144 return VTK_CONVEX_POINT_SET;
00145 }
00146 else return VTK_EMPTY_CELL;
00147
00148 default: return VTK_EMPTY_CELL;
00149 }
00150 }
00151
00152
00156
00157
00158 void SMESHGUI_MeshEditPreview::SetData (const SMESH::MeshPreviewStruct* previewData)
00159 {
00160
00161 const SMESH::nodes_array& aNodesXYZ = previewData->nodesXYZ;
00162 vtkPoints* aPoints = vtkPoints::New();
00163 aPoints->SetNumberOfPoints(aNodesXYZ.length());
00164
00165 for ( int i = 0; i < aNodesXYZ.length(); i++ ) {
00166 aPoints->SetPoint( i, aNodesXYZ[i].x, aNodesXYZ[i].y, aNodesXYZ[i].z );
00167 }
00168 myGrid->SetPoints(aPoints);
00169
00170 aPoints->Delete();
00171
00172
00173 const SMESH::long_array& anElemConnectivity = previewData->elementConnectivities;
00174 const SMESH::types_array& anElemTypes = previewData->elementTypes;
00175
00176 vtkIdType aCellsSize = anElemConnectivity.length() + anElemTypes.length();
00177 vtkIdType aNbCells = anElemTypes.length();
00178
00179 vtkCellArray* aConnectivity = vtkCellArray::New();
00180 aConnectivity->Allocate( aCellsSize, 0 );
00181
00182 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
00183 aCellTypesArray->SetNumberOfComponents( 1 );
00184 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
00185
00186 vtkIdList *anIdList = vtkIdList::New();
00187 int aNodePos = 0;
00188
00189 for ( int i = 0; i < anElemTypes.length(); i++ ) {
00190 const SMESH::ElementSubType& anElementSubType = anElemTypes[i];
00191 SMDSAbs_ElementType aType = SMDSAbs_ElementType(anElementSubType.SMDS_ElementType);
00192 vtkIdType aNbNodes = anElementSubType.nbNodesInElement;
00193 anIdList->SetNumberOfIds( aNbNodes );
00194
00195 for ( vtkIdType aNodeId = 0; aNodeId < aNbNodes; aNodeId++ ){
00196 anIdList->SetId( aNodeId, anElemConnectivity[aNodePos] );
00197 aNodePos++;
00198 }
00199
00200 aConnectivity->InsertNextCell( anIdList );
00201 aCellTypesArray->InsertNextValue( getCellType( aType,
00202 anElemTypes[i].isPoly,
00203 aNbNodes ) );
00204 }
00205 anIdList->Delete();
00206
00207
00208 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
00209 aCellLocationsArray->SetNumberOfComponents( 1 );
00210 aCellLocationsArray->SetNumberOfTuples( aNbCells );
00211
00212 aConnectivity->InitTraversal();
00213 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
00214 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
00215
00216 myGrid->SetCells( aCellTypesArray, aCellLocationsArray, aConnectivity );
00217
00218 myPreviewActor->GetMapper()->Update();
00219
00220 aCellTypesArray->Delete();
00221 aCellLocationsArray->Delete();
00222 aConnectivity->Delete();
00223
00224 SetVisibility(true);
00225 }
00226
00227
00231
00232
00233 void SMESHGUI_MeshEditPreview::SetVisibility (bool theVisibility)
00234 {
00235 myPreviewActor->SetVisibility(theVisibility);
00236 SMESH::RepaintCurrentView();
00237 }
00238
00239
00243
00244
00245 void SMESHGUI_MeshEditPreview::SetColor(double R, double G, double B)
00246 {
00247 myPreviewActor->SetColor( R, G, B );
00248 }
00249
00250
00254
00255 SALOME_Actor* SMESHGUI_MeshEditPreview::GetActor() const
00256 {
00257 return myPreviewActor;
00258 }