FEM Post: Move post processing to fem objects

This commit is contained in:
Stefan Tröger
2015-10-25 21:00:07 +01:00
committed by wmayer
parent 8805cab27c
commit 4d09c09dc0
26 changed files with 2732 additions and 457 deletions

View File

@@ -129,6 +129,7 @@
#include "WinNativeGestureRecognizers.h"
#include "Document.h"
/*
#include "SoVTKActor.h"
#include "vtkDataSetSurfaceFilter.h"
#include "vtkGeometryFilter.h"
@@ -146,7 +147,7 @@
#include "vtkRungeKutta4.h"
#include "vtkStreamTracer.h"
#include "vtkPointLocator.h"
*/
//#define FC_LOGGING_CB
using namespace Gui;
@@ -545,241 +546,7 @@ void View3DInventorViewer::init()
cursor = QBitmap::fromData(QSize(PAN_WIDTH, PAN_HEIGHT), pan_bitmap);
mask = QBitmap::fromData(QSize(PAN_WIDTH, PAN_HEIGHT), pan_mask_bitmap);
panCursor = QCursor(cursor, mask, PAN_HOT_X, PAN_HOT_Y);
//test vtk integration
vtkCubeSource* cube = vtkCubeSource::New();
source = vtkSmartPointer<vtkDataSetReader>::New();
source->SetFileName("/home/stefan/Downloads/pressure.vtk");
vtkGeometryFilter* f1 = vtkGeometryFilter::New();
f1->SetInputConnection(source->GetOutputPort());
f1->Update();
vtkPolyDataMapper* mapper_ = vtkPolyDataMapper::New();
mapper_->SetInputConnection(f1->GetOutputPort());
mapper_->Update();
vtkPolyData* data = mapper_->GetInput();
//try to color the data
vtkLookupTable* table = vtkLookupTable::New();
double range[2];
data->GetPointData()->GetArray(0)->GetRange(range, 0);
table->SetTableRange(range[0], range[1]);
table->Build();
vtkUnsignedCharArray* colors = vtkUnsignedCharArray::New();
colors->SetNumberOfComponents(3);
colors->SetName("Colors");
for(int i=0; i<data->GetNumberOfPoints(); ++i) {
//get the pressure at the point
double pressure = data->GetPointData()->GetArray(0)->GetComponent(i, 0);
double dcolor[3];
table->GetColor(pressure, dcolor);
unsigned char color[3];
for(unsigned int j=0; j<3; ++j)
color[j] = static_cast<unsigned char>(255*dcolor[j]);
colors->InsertNextTupleValue(color);
}
data->GetPointData()->SetScalars(colors);
SoVTKActor* actor = new SoVTKActor;
actor->ref();
actor->setMapper(mapper_);
pcViewProviderRoot->addChild(actor);
//contour plot (isosurface)
SoTranslation* trans = new SoTranslation();
trans->ref();
trans->translation.setValue(SbVec3f(15,15,5));
pcViewProviderRoot->addChild(trans);
SoVTKActor* actor2 = new SoVTKActor;
actor2->ref();
pcViewProviderRoot->addChild(actor2);
vtkContourFilter* contour = vtkContourFilter::New();
contour->SetValue(0, (range[0]+range[1])/2);
contour->SetInputConnection(source->GetOutputPort());
vtkGeometryFilter* gf = vtkGeometryFilter::New();
gf->SetInputConnection(contour->GetOutputPort());
vtkPolyDataMapper* mapper2 = vtkPolyDataMapper::New();
mapper2->SetInputConnection(gf->GetOutputPort());
mapper2->Update();
actor2->setMapper(mapper2);
//slice
trans = new SoTranslation();
trans->ref();
trans->translation.setValue(SbVec3f(15,15,5));
pcViewProviderRoot->addChild(trans);
SoVTKActor* actor3 = new SoVTKActor;
actor3->ref();
pcViewProviderRoot->addChild(actor3);
vtkPlane* plane = vtkPlane::New();
plane->SetOrigin(5,-4, 30);
plane->SetNormal(0.28, 0, 0.95);
vtkCutter* cutter = vtkCutter::New();
cutter->SetInputConnection(source->GetOutputPort());
cutter->SetCutFunction(plane);
cutter->Update();
vtkPolyDataMapper* mapper3 = vtkPolyDataMapper::New();
mapper3->SetInputConnection(cutter->GetOutputPort());
mapper3->Update();
data = mapper3->GetInput();
table = vtkLookupTable::New();
data->GetPointData()->GetArray(0)->GetRange(range, 0);
table->SetTableRange(range[0], range[1]);
table->Build();
colors = vtkUnsignedCharArray::New();
colors->SetNumberOfComponents(3);
colors->SetName("Colors");
for(int i=0; i<data->GetNumberOfPoints(); ++i) {
//get the pressure at the point
double pressure = data->GetPointData()->GetArray(0)->GetComponent(i, 0);
double dcolor[3];
table->GetColor(pressure, dcolor);
unsigned char color[3];
for(unsigned int j=0; j<3; ++j)
color[j] = static_cast<unsigned char>(255*dcolor[j]);
colors->InsertNextTupleValue(color);
}
data->GetPointData()->SetScalars(colors);
actor3->setMapper(mapper3);
//hedgehog
trans = new SoTranslation();
trans->ref();
trans->translation.setValue(SbVec3f(-30, -30, -30));
pcViewProviderRoot->addChild(trans);
SoVTKActor* actor4 = new SoVTKActor;
actor4->ref();
pcViewProviderRoot->addChild(actor4);
//vtkLookupTable* lut = vtkLookupTable::New();
vtkHedgeHog* hedge = vtkHedgeHog::New();
hedge->SetScaleFactor(0.001);
hedge->SetInputConnection(source->GetOutputPort());
vtkPolyDataMapper* mapper4 = vtkPolyDataMapper::New();
mapper4->SetInputConnection(hedge->GetOutputPort());
mapper4->Update();
data = mapper4->GetInput();
colors = vtkUnsignedCharArray::New();
colors->SetNumberOfComponents(3);
colors->SetName("Colors");
for(int i=0; i<data->GetNumberOfPoints(); ++i) {
unsigned char color[3];
color[0] = 255;
color[1] = 50;
color[2] = 50;
colors->InsertNextTupleValue(color);
}
data->GetPointData()->SetScalars(colors);
actor4->setMapper(mapper4);
//streamline
trans = new SoTranslation();
trans->ref();
trans->translation.setValue(SbVec3f(15, 15, 5));
pcViewProviderRoot->addChild(trans);
SoVTKActor* actor6 = new SoVTKActor;
actor6->ref();
pcViewProviderRoot->addChild(actor6);
vtkPointSource* point = vtkPointSource::New();
point->SetRadius(3);
point->SetCenter(source->GetOutput()->GetCenter());
point->SetNumberOfPoints(100);
vtkRungeKutta4* runge = vtkRungeKutta4::New();
vtkStreamTracer* stream = vtkStreamTracer::New();
stream->SetInputConnection(source->GetOutputPort());
stream->SetSourceConnection(point->GetOutputPort());
stream->SetMaximumPropagation(100);
stream->SetMaximumIntegrationStep(0.01);
stream->SetIntegrationDirection(vtkStreamTracer::BOTH);
stream->SetIntegrator(runge);
vtkPolyDataMapper* mapper6 = vtkPolyDataMapper::New();
mapper6->SetInputConnection(stream->GetOutputPort());
mapper6->Update();
data = mapper6->GetInput();
//see which cell data we got
for(int i=0; i<data->GetPointData()->GetNumberOfArrays(); ++i) {
Base::Console().Message("Point data:\nArray %s (Type: %i)\n", data->GetPointData()->GetArrayName(i),
data->GetPointData()->GetArrayName(i));
}
for(int i=0; i<data->GetCellData()->GetNumberOfArrays(); ++i) {
Base::Console().Message("\nCell data:\nArray %s (Type: %i)", data->GetCellData()->GetArrayName(i),
data->GetCellData()->GetArrayName(i));
}
table = vtkLookupTable::New();
data->GetPointData()->GetArray(7)->GetRange(range, 0);
table->SetTableRange(range[0], range[1]);
Base::Console().Message("range: %d - %d\n", range[0], range[1]);
table->Build();
colors = vtkUnsignedCharArray::New();
colors->SetNumberOfComponents(3);
colors->SetName("Colors");
for(int i=0; i<data->GetNumberOfPoints(); ++i) {
//get the pressure at the point
double pressure = data->GetPointData()->GetArray(7)->GetComponent(i, 0);
//Base::Console().Message("angular velocity: %d\n", pressure);
double dcolor[3];
table->GetColor(pressure, dcolor);
unsigned char color[3];
for(unsigned int j=0; j<3; ++j)
color[j] = static_cast<unsigned char>(255*dcolor[j]);
colors->InsertNextTupleValue(color);
}
data->GetPointData()->SetScalars(colors);
actor6->setMapper(mapper6);
//glyph
trans = new SoTranslation();
trans->ref();
trans->translation.setValue(SbVec3f(15, 15, 5));
pcViewProviderRoot->addChild(trans);
SoVTKActor* actor5 = new SoVTKActor;
actor5->ref();
pcViewProviderRoot->addChild(actor5);
// vtkArrowSource* arrow = vtkArrowSource::New();
// arrow->SetTipRadius(0.1);
// arrow->SetTipLength(0.35);
// arrow->SetShaftRadius(0.03);
// arrow->SetTipResolution(4);
// arrow->SetShaftResolution(4);
// vtkGlyph3D* glyph = vtkGlyph3D::New();
// glyph->SetInputConnection(source->GetOutputPort());
// //glyph->SetSourceConnection(arrow->GetOutputPort());
// vtkPolyDataMapper* mapper5 = vtkPolyDataMapper::New();
// mapper5->SetInputConnection(glyph->GetOutputPort());
// mapper5->Update();
// actor5->setMapper(mapper5);
}
View3DInventorViewer::~View3DInventorViewer()