Skip to content

Commit

Permalink
Moveable 3D mesh planes
Browse files Browse the repository at this point in the history
  • Loading branch information
thliebig committed Apr 10, 2012
1 parent 444b032 commit be052cd
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 11 deletions.
76 changes: 76 additions & 0 deletions QCSGridEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,48 @@ QToolBar* QCSGridEditor::BuildToolbar()
return TB;
}

QWidget* QCSGridEditor::BuildPlanePosWidget()
{
QWidget* PPWid = new QWidget();
QGridLayout* lay = new QGridLayout();

for (int n=0;n<3;++n)
{
m_NormNames[n] = new QLabel(GetNormName(n)+ tr(" plane:"));
lay->addWidget( m_NormNames[n] ,n,0);
m_PlanePos[n] = new QSlider();
m_PlanePos[n]->setOrientation(Qt::Horizontal);
lay->addWidget(m_PlanePos[n],n,1);
m_PlanePosValue[n] = new QLabel();
lay->addWidget(m_PlanePosValue[n],n,2);
}
QObject::connect(m_PlanePos[0],SIGNAL(valueChanged(int)),this,SIGNAL(GridPlaneXChanged(int)));
QObject::connect(m_PlanePos[1],SIGNAL(valueChanged(int)),this,SIGNAL(GridPlaneYChanged(int)));
QObject::connect(m_PlanePos[2],SIGNAL(valueChanged(int)),this,SIGNAL(GridPlaneZChanged(int)));

QObject::connect(m_PlanePos[0],SIGNAL(valueChanged(int)),this,SLOT(SetGridPlaneX(int)));
QObject::connect(m_PlanePos[1],SIGNAL(valueChanged(int)),this,SLOT(SetGridPlaneY(int)));
QObject::connect(m_PlanePos[2],SIGNAL(valueChanged(int)),this,SLOT(SetGridPlaneZ(int)));

PPWid->setLayout(lay);
return PPWid;
}

void QCSGridEditor::SetGridPlaneX(int pos)
{
m_PlanePosValue[0]->setText(QString("%1 = %2").arg(GetDirName(0)).arg(clGrid->GetLine(0,pos)));
}

void QCSGridEditor::SetGridPlaneY(int pos)
{
m_PlanePosValue[1]->setText(QString("%1 = %2").arg(GetDirName(1)).arg(clGrid->GetLine(1,pos)));
}

void QCSGridEditor::SetGridPlaneZ(int pos)
{
m_PlanePosValue[2]->setText(QString("%1 = %2").arg(GetDirName(2)).arg(clGrid->GetLine(2,pos)));
}

void QCSGridEditor::BuildInHomogenDisc()
{
QDialog* HomogenDisc = new QDialog();
Expand Down Expand Up @@ -510,7 +552,12 @@ void QCSGridEditor::Update()
SimBox.at(2*i+1)->setText(QString("%1").arg(clGrid->GetLine(i,clGrid->GetQtyLines(i)-1)));
NodeQty.at(i)->setText(QString("%1").arg(clGrid->GetQtyLines(i)));
m_DirNames[i]->setText(GetDirName(i));
m_PlanePos[i]->setRange(0,clGrid->GetQtyLines(i)-1);
m_NormNames[i]->setText(GetNormName(i)+ tr(" plane: "));
}
SetGridPlaneX(m_PlanePos[0]->value());
SetGridPlaneY(m_PlanePos[0]->value());
SetGridPlaneZ(m_PlanePos[0]->value());
UnitLength->setText(QString("%1").arg(clGrid->GetDeltaUnit()));
emit GridChanged();
}
Expand Down Expand Up @@ -548,3 +595,32 @@ QString QCSGridEditor::GetDirName(int ny)
}
return "";
}

QString QCSGridEditor::GetNormName(int ny)
{
if (clGrid->GetMeshType()==0)
{
switch (ny)
{
case 0:
return "yz";
case 1:
return "zx";
case 2:
return "xy";
}
}
if (clGrid->GetMeshType()==1)
{
switch (ny)
{
case 0:
return QString(QChar(0xb1, 0x03)) + "z";
case 1:
return "zr";
case 2:
return "r" + QString(QChar(0xb1, 0x03));
}
}
return "";
}
15 changes: 13 additions & 2 deletions QCSGridEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@ class QCSGridEditor : public QWidget
virtual ~QCSGridEditor();

QToolBar* BuildToolbar();
QWidget* BuildPlanePosWidget();

QString GetDirName(int ny);
QString GetNormName(int ny);

signals:
void OpacityChange(int);
void signalDetectEdges(int);
void GridChanged();
void GridPlaneXChanged(int);
void GridPlaneYChanged(int);
void GridPlaneZChanged(int);

public slots:
void Update();
Expand All @@ -43,6 +50,9 @@ public slots:
void EditY();
void EditZ();
void Edit(int direct);
void SetGridPlaneX(int pos);
void SetGridPlaneY(int pos);
void SetGridPlaneZ(int pos);

protected slots:
void BuildHomogenDisc();
Expand All @@ -59,8 +69,9 @@ protected slots:
QLineEdit* UnitLength;
QSlider* OpacitySlider;
QLabel* m_DirNames[3];

QString GetDirName(int ny);
QSlider* m_PlanePos[3];
QLabel* m_NormNames[3];
QLabel* m_PlanePosValue[3];

double* GetDoubleArrayFromString(int *count, QString qsValue);
};
Expand Down
10 changes: 10 additions & 0 deletions QCSXCAD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ QCSXCAD::QCSXCAD(QWidget *parent) : QMainWindow(parent)
QObject::connect(GridEditor,SIGNAL(OpacityChange(int)),StructureVTK,SLOT(SetGridOpacity(int)));
QObject::connect(GridEditor,SIGNAL(signalDetectEdges(int)),this,SLOT(DetectEdges(int)));
QObject::connect(GridEditor,SIGNAL(GridChanged()),StructureVTK,SLOT(RenderGrid()));
QObject::connect(GridEditor,SIGNAL(GridPlaneXChanged(int)),StructureVTK,SLOT(RenderGridX(int)));
QObject::connect(GridEditor,SIGNAL(GridPlaneYChanged(int)),StructureVTK,SLOT(RenderGridY(int)));
QObject::connect(GridEditor,SIGNAL(GridPlaneZChanged(int)),StructureVTK,SLOT(RenderGridZ(int)));

dock = new QDockWidget(tr("Rectilinear Grid"),this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea);
Expand All @@ -123,6 +126,13 @@ QCSXCAD::QCSXCAD(QWidget *parent) : QMainWindow(parent)
QObject::connect(QParaSet,SIGNAL(ParameterChanged()),this,SLOT(setModified()));
clParaSet=QParaSet;

dock = new QDockWidget(tr("Rectilinear Grid - Plane Position"),this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea);
dock->setWidget(GridEditor->BuildPlanePosWidget());
dock->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);
dock->setObjectName("Grid_Plane_Pos");
addDockWidget(Qt::LeftDockWidgetArea,dock);

dock = new QDockWidget(tr("Parameter"),this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea);
dock->setWidget(QParaSet);
Expand Down
39 changes: 31 additions & 8 deletions QVTKStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,28 @@ void QVTKStructure::RenderGrid()
RenderGridDir(0,0);
RenderGridDir(1,0);
RenderGridDir(2,0);
SetGridOpacity(GridOpacity);
}

void QVTKStructure::RenderGridDir(int dir, int plane_pos)
void QVTKStructure::RenderGridX(int plane_pos)
{
RenderGridDir(0,plane_pos);
VTKWidget->GetRenderWindow()->GetInteractor()->Render();
}

void QVTKStructure::RenderGridY(int plane_pos)
{
RenderGridDir(1,plane_pos);
VTKWidget->GetRenderWindow()->GetInteractor()->Render();

}

void QVTKStructure::RenderGridZ(int plane_pos)
{
RenderGridDir(2,plane_pos);
VTKWidget->GetRenderWindow()->GetInteractor()->Render();
}

void QVTKStructure::RenderGridDir(int dir, unsigned int plane_pos)
{
if (ActorGridPlane[dir]!=NULL)
{
Expand All @@ -241,6 +259,11 @@ void QVTKStructure::RenderGridDir(int dir, int plane_pos)

for (int n=0;n<3;++n)
uiQty[n]=CSGrid->GetQtyLines(n);
if (plane_pos>=uiQty[dir])
{
cerr << "QVTKStructure::RenderGridDir: requested plane postion is out of range, resetting to max value!" << endl;
plane_pos = uiQty[dir]-1;
}

if (CSGrid->GetMeshType()==CARTESIAN)
{
Expand All @@ -257,7 +280,7 @@ void QVTKStructure::RenderGridDir(int dir, int plane_pos)
grid_plane->SetInput(m_Rect_Grid);
switch (dir)
{
case 0:
case 2:
{
grid_plane->SetExtent(0,uiQty[0]-1, 0,uiQty[1]-1, plane_pos,plane_pos);
break;
Expand All @@ -267,7 +290,7 @@ void QVTKStructure::RenderGridDir(int dir, int plane_pos)
grid_plane->SetExtent(0,uiQty[0]-1, plane_pos,plane_pos, 0,uiQty[2]-1);
break;
}
case 2:
case 0:
{
grid_plane->SetExtent(plane_pos,plane_pos, 0,uiQty[1]-1, 0,uiQty[2]-1);
break;
Expand All @@ -285,13 +308,12 @@ void QVTKStructure::RenderGridDir(int dir, int plane_pos)
return;
}

// draw only planes r-a (0) and r-z (1), plane z-a (2) obstructs the view on the structure
vtkStructuredGridGeometryFilter *grid_plane = vtkStructuredGridGeometryFilter::New();
plane = grid_plane;
grid_plane->SetInput(m_Struct_Grid);
switch (dir)
{
case 0:
case 2:
{
grid_plane->SetExtent(0,uiQty[0]-1, 0,uiQty[1]-1, plane_pos,plane_pos);
break;
Expand All @@ -301,8 +323,8 @@ void QVTKStructure::RenderGridDir(int dir, int plane_pos)
grid_plane->SetExtent(0,uiQty[0]-1, plane_pos,plane_pos, 0,uiQty[2]-1);
break;
}
case 2:
{ // skipped, see above, plane z-a obstructs the view on the structure
case 0:
{
grid_plane->SetExtent(plane_pos,plane_pos, 0,uiQty[1]-1, 0,uiQty[2]-1);
break;
}
Expand All @@ -317,6 +339,7 @@ void QVTKStructure::RenderGridDir(int dir, int plane_pos)
ActorGridPlane[dir]->GetProperty()->SetDiffuse(0);
ActorGridPlane[dir]->GetProperty()->SetAmbient(1);
ActorGridPlane[dir]->GetProperty()->SetRepresentationToWireframe();
ActorGridPlane[dir]->GetProperty()->SetOpacity((double)GridOpacity/255.0);
ren->AddActor(ActorGridPlane[dir]);
gridMapper->Delete();
plane->Delete();
Expand Down
5 changes: 4 additions & 1 deletion QVTKStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public slots:
void setZX();
void SetPropOpacity(unsigned int uiID, int val);
void RenderGrid();
void RenderGridX(int plane_pos);
void RenderGridY(int plane_pos);
void RenderGridZ(int plane_pos);
void RenderGeometry();

//! Export the current view to an image file (currently only png)
Expand All @@ -71,7 +74,7 @@ public slots:
void ExportProperty2STL(unsigned int uiID, QString filename, double scale = 1.0);

protected slots:
void RenderGridDir(int dir, int plane_pos);
void RenderGridDir(int dir, unsigned int plane_pos);

protected:
typedef struct
Expand Down

0 comments on commit be052cd

Please sign in to comment.