bug 11772. Fix

2) impossible to create an quadratic pyramid and pentahedron from menu
Modification-Add
3) in preview of "Add Quadratic Tetrahedron" - orientation is not shown (use
"Reverse" button)?> impossible to create required orientation.
This commit is contained in:
eap 2006-03-03 13:52:14 +00:00
parent 28b1248d96
commit 261d5abd90

View File

@ -62,6 +62,46 @@ using namespace std;
namespace SMESH { namespace SMESH {
void ReverseConnectivity( vector<int> & ids, int type )
{
// for reverse connectivity of other types keeping the first id, see
// void SMESH_VisualObjDef::buildElemPrs() in SMESH_Object.cxx:900
const int* conn = 0;
switch ( type ) {
case QUAD_TETRAHEDRON: {
static int aConn[] = {0,2,1,3,6,5,4,7,9,8};
conn = aConn;
break;
}
case QUAD_PYRAMID: {
static int aConn[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
conn = aConn;
break;
}
case QUAD_PENTAHEDRON: {
static int aConn[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
conn = aConn;
break;
}
case QUAD_HEXAHEDRON: {
static int aConn[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
conn = aConn;
break;
}
default:;
}
if ( !conn ) {
reverse( ids.begin(), ids.end() );
}
else {
vector<int> aRevIds( ids.size() );
for ( int i = 0; i < ids.size(); i++)
aRevIds[ i ] = ids[ conn[ i ]];
ids = aRevIds;
}
}
class TElementSimulation { class TElementSimulation {
SalomeApp_Application* myApplication; SalomeApp_Application* myApplication;
SUIT_ViewWindow* myViewWindow; SUIT_ViewWindow* myViewWindow;
@ -70,6 +110,9 @@ namespace SMESH {
SALOME_Actor* myPreviewActor; SALOME_Actor* myPreviewActor;
vtkDataSetMapper* myMapper; vtkDataSetMapper* myMapper;
vtkUnstructuredGrid* myGrid; vtkUnstructuredGrid* myGrid;
//vtkProperty* myBackProp, *myProp;
float anRGB[3], aBackRGB[3];
public: public:
TElementSimulation (SalomeApp_Application* theApplication) TElementSimulation (SalomeApp_Application* theApplication)
@ -91,82 +134,83 @@ namespace SMESH {
myPreviewActor->VisibilityOff(); myPreviewActor->VisibilityOff();
myPreviewActor->SetMapper(myMapper); myPreviewActor->SetMapper(myMapper);
float anRGB[3]; vtkProperty* myProp = vtkProperty::New();
vtkProperty* aProp = vtkProperty::New();
GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) ); GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] ); myProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
myPreviewActor->SetProperty( aProp ); myPreviewActor->SetProperty( myProp );
aProp->Delete(); myProp->Delete();
vtkProperty* aBackProp = vtkProperty::New(); vtkProperty* myBackProp = vtkProperty::New();
GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) ); GetColor( "SMESH", "backface_color", aBackRGB[0], aBackRGB[1], aBackRGB[2], QColor( 0, 0, 255 ) );
aBackProp->SetColor( anRGB[0], anRGB[1], anRGB[2] ); myBackProp->SetColor( aBackRGB[0], aBackRGB[1], aBackRGB[2] );
myPreviewActor->SetBackfaceProperty( aBackProp ); myPreviewActor->SetBackfaceProperty( myBackProp );
aBackProp->Delete(); myBackProp->Delete();
myVTKViewWindow->AddActor(myPreviewActor); myVTKViewWindow->AddActor(myPreviewActor);
} }
typedef std::vector<vtkIdType> TVTKIds; typedef std::vector<vtkIdType> TVTKIds;
void SetPosition (SMESH_Actor* theActor, void SetPosition (SMESH_Actor* theActor,
vtkIdType theType, const int theType,
const TVTKIds& theIds, TVTKIds& theIds,
int theMode) const int theMode,
const bool theReverse)
{ {
vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid(); vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
myGrid->SetPoints(aGrid->GetPoints()); myGrid->SetPoints(aGrid->GetPoints());
//add points //add points
const int* aConn = NULL; vtkIdType aType = 0;
/*
switch (theType) { switch (theType) {
case VTK_QUADRATIC_TRIANGLE: case QUAD_EDGE:
{ aType = VTK_QUADRATIC_EDGE;
static int anIds[] = {0,2,1,5,4,3}; break;
aConn = anIds; case QUAD_TRIANGLE:
aType = VTK_QUADRATIC_TRIANGLE;
break;
case QUAD_QUADRANGLE:
aType = VTK_QUADRATIC_QUAD;
break;
case QUAD_TETRAHEDRON:
aType = VTK_QUADRATIC_TETRA;
break;
case QUAD_PYRAMID:
//aType = VTK_QUADRATIC_PYRAMID; // NOT SUPPORTED IN VTK4.2
aType = VTK_CONVEX_POINT_SET;
break;
case QUAD_PENTAHEDRON:
//aType = VTK_QUADRATIC_WEDGE; // NOT SUPPORTED IN VTK4.2
aType = VTK_CONVEX_POINT_SET;
break;
case QUAD_HEXAHEDRON:
aType = VTK_QUADRATIC_HEXAHEDRON;
break; break;
} }
case VTK_QUADRATIC_QUAD: // take care of orientation
{ if ( aType == VTK_CONVEX_POINT_SET ) {
static int anIds[] = {0,3,2,1,7,6,5,4}; if ( theReverse && theMode == VTK_SURFACE ) {
aConn = anIds; //myPreviewActor->GetProperty()->SetColor( aBackRGB[0], aBackRGB[1], aBackRGB[2] );
break; }
} }
case VTK_QUADRATIC_TETRA: else {
{ // VTK cell connectivity opposites the MED one
static int anIds[] = {0,2,1,3,6,5,4,7,9,8}; if ( !theReverse ) {
aConn = anIds; ReverseConnectivity( theIds, theType );
break;
}
case VTK_QUADRATIC_PYRAMID:
{
static int anIds[] = {0,3,2,1,4,9,12,11,10};
aConn = anIds;
break;
}
case VTK_QUADRATIC_HEXAHEDRON:
{
static int anIds[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
aConn = anIds;
break;
} }
} }
*/
myGrid->Reset(); myGrid->Reset();
vtkIdList *anIds = vtkIdList::New(); vtkIdList *anIds = vtkIdList::New();
if(aConn) for (int i = 0, iEnd = theIds.size(); i < iEnd; i++) {
for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
anIds->InsertId(i,theIds[aConn[i]]);
else
for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
anIds->InsertId(i,theIds[i]); anIds->InsertId(i,theIds[i]);
//std::cout << i<< ": " << theIds[i] << std::endl;
}
myGrid->InsertNextCell(theType,anIds); myGrid->InsertNextCell(aType,anIds);
anIds->Delete(); anIds->Delete();
myGrid->Modified(); myGrid->Modified();
@ -174,6 +218,13 @@ namespace SMESH {
myPreviewActor->GetMapper()->Update(); myPreviewActor->GetMapper()->Update();
myPreviewActor->SetRepresentation( theMode ); myPreviewActor->SetRepresentation( theMode );
SetVisibility(true); SetVisibility(true);
// restore normal orientation
if ( aType == VTK_CONVEX_POINT_SET ) {
if ( theReverse && theMode == VTK_SURFACE ) {
//myPreviewActor->GetProperty()->SetColor( anRGB[0], anRGB[1], anRGB[2] );
}
}
} }
@ -195,6 +246,9 @@ namespace SMESH {
myMapper->Delete(); myMapper->Delete();
myGrid->Delete(); myGrid->Delete();
// myProp->Delete();
// myBackProp->Delete();
} }
}; };
} }
@ -210,11 +264,11 @@ static int LastTriangleIds[] = {1,2,0};
static int FirstQuadrangleIds[] = {0,1,2,3}; static int FirstQuadrangleIds[] = {0,1,2,3};
static int LastQuadrangleIds[] = {1,2,3,0}; static int LastQuadrangleIds[] = {1,2,3,0};
static int FirstTetrahedronIds[] = {0,1,2,3,1,2}; static int FirstTetrahedronIds[] = {0,1,2,3,3,3};
static int LastTetrahedronIds[] = {1,2,0,0,3,3}; static int LastTetrahedronIds[] = {1,2,0,0,1,2};
static int FirstPyramidIds[] = {0,1,2,3,4,1,2,3}; static int FirstPyramidIds[] = {0,1,2,3,4,4,4,4};
static int LastPyramidIds[] = {1,2,3,0,0,4,4,4}; static int LastPyramidIds[] = {1,2,3,0,0,1,2,3};
static int FirstPentahedronIds[] = {0,1,2,3,4,5,0,1,2}; static int FirstPentahedronIds[] = {0,1,2,3,4,5,0,1,2};
static int LastPentahedronIds[] = {1,2,0,4,5,3,3,4,5}; static int LastPentahedronIds[] = {1,2,0,4,5,3,3,4,5};
@ -419,7 +473,7 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
myNbCorners = 5; myNbCorners = 5;
break; break;
case QUAD_PENTAHEDRON: case QUAD_PENTAHEDRON:
aNumRows = 8; aNumRows = 9;
myNbCorners = 6; myNbCorners = 6;
break; break;
case QUAD_HEXAHEDRON: case QUAD_HEXAHEDRON:
@ -496,13 +550,13 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
if (IsValid() && !mySMESHGUI->isActiveStudyLocked()) { if (IsValid() && !mySMESHGUI->isActiveStudyLocked()) {
myBusy = true; myBusy = true;
QStringList aListId; vector<int> anIds;
switch (myType) { switch (myType) {
case QUAD_EDGE: case QUAD_EDGE:
aListId.append(myTable->text(0, 0)); anIds.push_back(myTable->text(0, 0).toInt());
aListId.append(myTable->text(0, 1)); anIds.push_back(myTable->text(0, 2).toInt());
aListId.append(myTable->text(0, 2)); anIds.push_back(myTable->text(0, 1).toInt());
break; break;
case QUAD_TRIANGLE: case QUAD_TRIANGLE:
case QUAD_QUADRANGLE: case QUAD_QUADRANGLE:
@ -511,23 +565,20 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
case QUAD_PENTAHEDRON: case QUAD_PENTAHEDRON:
case QUAD_HEXAHEDRON: case QUAD_HEXAHEDRON:
for ( int row = 0; row < myNbCorners; row++ ) for ( int row = 0; row < myNbCorners; row++ )
aListId.append(myTable->text(row, 0)); anIds.push_back(myTable->text(row, 0).toInt());
for ( int row = 0; row < myTable->numRows(); row++ ) for ( int row = 0; row < myTable->numRows(); row++ )
aListId.append(myTable->text(row, 1)); anIds.push_back(myTable->text(row, 1).toInt());
break; break;
} }
if ( myReverseCB->isChecked())
SMESH::ReverseConnectivity( anIds, myType );
int aNumberOfIds = aListId.count(); int aNumberOfIds = anIds.size();
SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array; SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
anArrayOfIdeces->length( aNumberOfIds ); anArrayOfIdeces->length( aNumberOfIds );
bool reverse = (myReverseCB->isChecked());
for (int i = 0; i < aNumberOfIds; i++) for (int i = 0; i < aNumberOfIds; i++)
if (reverse) anArrayOfIdeces[i] = anIds[ i ];
anArrayOfIdeces[i] = aListId[ aNumberOfIds - i - 1 ].toInt();
else
anArrayOfIdeces[i] = aListId[ i ].toInt();
SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
switch (myType) { switch (myType) {
@ -735,10 +786,10 @@ void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
if ( myType == QUAD_EDGE ) if ( myType == QUAD_EDGE )
{ {
anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 0).toInt() ) ); anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 0).toInt() ) );
anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 2).toInt() ) );
anID = (myTable->text(0, 1)).toInt(&ok); anID = (myTable->text(0, 1)).toInt(&ok);
if (!ok) anID = (myTable->text(0, 0)).toInt(); if (!ok) anID = (myTable->text(0, 0)).toInt();
anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) ); anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 2).toInt() ) );
aDisplayMode = VTK_WIREFRAME; aDisplayMode = VTK_WIREFRAME;
} }
else else
@ -757,38 +808,7 @@ void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
} }
} }
if (myReverseCB->isChecked()) mySimulation->SetPosition(myActor,myType,anIds,aDisplayMode,myReverseCB->isChecked());
reverse(anIds.begin(),anIds.end());
vtkIdType aType = 0;
switch (myType) {
case QUAD_EDGE:
aType = VTK_QUADRATIC_EDGE;
break;
case QUAD_TRIANGLE:
aType = VTK_QUADRATIC_TRIANGLE;
break;
case QUAD_QUADRANGLE:
aType = VTK_QUADRATIC_QUAD;
break;
case QUAD_TETRAHEDRON:
aType = VTK_QUADRATIC_TETRA;
break;
/*
case QUAD_PYRAMID:
aType = VTK_QUADRATIC_PYRAMID; // NOT SUPPORTED IN VTK4.2
break;
case QUAD_PENTAHEDRON:
aType = VTK_QUADRATIC_WEDGE; // NOT SUPPORTED IN VTK4.2
break;
*/
case QUAD_HEXAHEDRON:
aType = VTK_QUADRATIC_HEXAHEDRON;
break;
}
mySimulation->SetPosition(myActor,aType,anIds,aDisplayMode);
SMESH::UpdateView(); SMESH::UpdateView();
} }
} }