Commit 49503788 authored by mat's avatar mat
Browse files

Add the possibility to make a cube network made of lines.

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@201 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 67483be5
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#include <vtkPoints.h> #include <vtkPoints.h>
#include <vtkSmartPointer.h> #include <vtkSmartPointer.h>
#include <vtkHexahedron.h> #include <vtkHexahedron.h>
#include <vtkUnstructuredGrid.h> #include <vtkLine.h>
#include <vtkCellArray.h> #include <vtkCellArray.h>
GridTopology::GridTopology(ActionExtension *extension) : Action(extension) { GridTopology::GridTopology(ActionExtension *extension) : Action(extension) {
...@@ -50,6 +50,7 @@ GridTopology::GridTopology(ActionExtension *extension) : Action(extension) { ...@@ -50,6 +50,7 @@ GridTopology::GridTopology(ActionExtension *extension) : Action(extension) {
addTag("Build Grid"); addTag("Build Grid");
setProperty("Tetrahedralize", false); setProperty("Tetrahedralize", false);
setProperty("Network", false);
setProperty("Dimension X", 1); setProperty("Dimension X", 1);
setProperty("Dimension Y", 1); setProperty("Dimension Y", 1);
setProperty("Dimension Z", 1); setProperty("Dimension Z", 1);
...@@ -91,13 +92,40 @@ Action::ApplyStatus GridTopology::apply() { ...@@ -91,13 +92,40 @@ Action::ApplyStatus GridTopology::apply() {
points->InsertNextPoint(pt); points->InsertNextPoint(pt);
} }
vtkSmartPointer<vtkUnstructuredGrid> grid = vtkSmartPointer<vtkUnstructuredGrid>::New();
grid->SetPoints(points);
if (property("Network").toBool()) {
buildNetwork(grid);
}
else {
buildGrid(grid);
}
grid->Update();
MeshComponent* result = new MeshComponent(grid, "Grid_" + QString::number(dimX)+"x"+QString::number(dimY)+"x"+QString::number(dimZ));
Application::refresh();
Application::resetProgressBar();
Application::showStatusBarMessage("");
return SUCCESS;
}
void GridTopology::buildGrid(vtkSmartPointer<vtkUnstructuredGrid> grid) {
vtkSmartPointer<vtkCellArray> elements = vtkSmartPointer<vtkCellArray>::New(); vtkSmartPointer<vtkCellArray> elements = vtkSmartPointer<vtkCellArray>::New();
vtkSmartPointer<vtkHexahedron> element; vtkSmartPointer<vtkHexahedron> element = vtkSmartPointer<vtkHexahedron>::New();
int dimX = property("Dimension X").toInt();
int dimY = property("Dimension Y").toInt();
int dimZ = property("Dimension Z").toInt();
for (int i=1; i<=dimX; i++) for (int i=1; i<=dimX; i++)
for (int j=1; j<=dimY; j++) for (int j=1; j<=dimY; j++)
for (int k=1; k<=dimZ; k++) { for (int k=1; k<=dimZ; k++) {
element = vtkSmartPointer<vtkHexahedron>::New();
element->GetPointIds()->SetId (0, (((i-1)*(dimY+1))+j-1)*(dimZ+1)+k-1); element->GetPointIds()->SetId (0, (((i-1)*(dimY+1))+j-1)*(dimZ+1)+k-1);
element->GetPointIds()->SetId (1, (((i-1)*(dimY+1))+j)*(dimZ+1)+k-1); element->GetPointIds()->SetId (1, (((i-1)*(dimY+1))+j)*(dimZ+1)+k-1);
...@@ -111,16 +139,74 @@ Action::ApplyStatus GridTopology::apply() { ...@@ -111,16 +139,74 @@ Action::ApplyStatus GridTopology::apply() {
elements->InsertNextCell ( element ); elements->InsertNextCell ( element );
} }
vtkSmartPointer<vtkUnstructuredGrid> grid = vtkSmartPointer<vtkUnstructuredGrid>::New(); //grid->Allocate(dimX*dimY*dimZ);
grid->Allocate(dimX*dimY*dimZ);
grid->SetCells(VTK_HEXAHEDRON, elements); grid->SetCells(VTK_HEXAHEDRON, elements);
grid->SetPoints(points); }
grid->Update();
MeshComponent* result = new MeshComponent(grid, "Grid_" + QString::number(dimX)+"x"+QString::number(dimY)+"x"+QString::number(dimZ)); void GridTopology::buildNetwork(vtkSmartPointer<vtkUnstructuredGrid> grid) {
Application::refresh(); vtkSmartPointer<vtkCellArray> elements = vtkSmartPointer<vtkCellArray>::New();
Application::resetProgressBar(); vtkSmartPointer<vtkLine> element = vtkSmartPointer<vtkLine>::New();
Application::showStatusBarMessage("");
return SUCCESS; int dimX = property("Dimension X").toInt();
int dimY = property("Dimension Y").toInt();
int dimZ = property("Dimension Z").toInt();
for (int i=1; i<=dimX; i++)
for (int j=0; j<=dimY; j++)
for (int k=0; k<=dimZ; k++) {
element->GetPointIds()->SetId (0, (((i-1)*( dimY + 1 ))+j)*( dimZ + 1 )+k);
element->GetPointIds()->SetId (1, ((i*( dimY + 1 ))+j)*( dimZ + 1 )+k);
elements->InsertNextCell ( element );
}
for (int i=0; i<=dimX; i++)
for (int j=1; j<=dimY; j++)
for (int k=0; k<=dimZ; k++) {
element->GetPointIds()->SetId (0, ( ( i * ( dimY + 1 ) ) + j - 1 ) * ( dimZ + 1 ) +k );
element->GetPointIds()->SetId (1, ( ( i * ( dimY + 1 ) ) + j ) * ( dimZ + 1 ) + k );
elements->InsertNextCell ( element );
}
for (int i=0; i<=dimX; i++)
for (int j=0; j<=dimY; j++)
for (int k=1; k<=dimZ; k++) {
element->GetPointIds()->SetId (0, ((i*( dimY + 1 ))+j)*( dimZ + 1 )+k-1);
element->GetPointIds()->SetId (1, ((i*( dimY + 1 ))+j)*( dimZ + 1 )+k);
elements->InsertNextCell ( element );
}
for (int i=1; i<=dimX; i++)
for (int j=1; j<=dimY; j++)
for (int k=1; k<=dimZ; k++) {
element->GetPointIds()->SetId (0, (((i-1)*( dimY + 1 ))+j-1)*( dimZ + 1 )+k-1);
element->GetPointIds()->SetId (1, ((i*( dimY + 1 ))+j)*( dimZ + 1 )+k);
elements->InsertNextCell ( element );
}
for (int i=1; i<=dimX; i++)
for (int j=1; j<=dimY; j++)
for (int k=1; k<=dimZ; k++) {
element->GetPointIds()->SetId (0, (((i-1)*( dimY + 1 ))+j)*( dimZ + 1 )+k);
element->GetPointIds()->SetId (1, ((i*( dimY + 1 ))+j-1)*( dimZ + 1 )+k-1);
elements->InsertNextCell ( element );
}
for (int i=1; i<=dimX; i++)
for (int j=1; j<=dimY; j++)
for (int k=1; k<=dimZ; k++) {
element->GetPointIds()->SetId (0, (((i-1)*( dimY + 1 ))+j-1)*( dimZ + 1 )+k);
element->GetPointIds()->SetId (1, ((i*( dimY + 1 ))+j)*( dimZ + 1 )+k-1);
elements->InsertNextCell ( element );
}
for (int i=1; i<=dimX; i++)
for (int j=1; j<=dimY; j++)
for (int k=1; k<=dimZ; k++) {
element->GetPointIds()->SetId (0, (((i-1)*( dimY + 1 ))+j)*( dimZ + 1 )+k-1);
element->GetPointIds()->SetId (1, ((i*( dimY + 1 ))+j-1)*( dimZ + 1 )+k);
elements->InsertNextCell ( element );
}
grid->SetCells(VTK_LINE, elements);
} }
\ No newline at end of file
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
#ifndef GRID_TOPOLOGY_HPP_ #ifndef GRID_TOPOLOGY_HPP_
#define GRID_TOPOLOGY_HPP_ #define GRID_TOPOLOGY_HPP_
#include <vtkUnstructuredGrid.h>
#include <vtkSmartPointer.h>
#include <Action.h> #include <Action.h>
using namespace camitk; using namespace camitk;
...@@ -55,6 +58,10 @@ private: ...@@ -55,6 +58,10 @@ private:
/// method called when the action is applied /// method called when the action is applied
virtual ApplyStatus apply(); virtual ApplyStatus apply();
void buildGrid(vtkSmartPointer<vtkUnstructuredGrid> grid);
void buildNetwork(vtkSmartPointer<vtkUnstructuredGrid> grid);
}; };
#endif // GRID_TOPOLOGY_HPP_ #endif // GRID_TOPOLOGY_HPP_
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment