FEM Post: Proof of concept

This commit is contained in:
Stefan Tröger 2015-04-19 16:09:52 +02:00 committed by wmayer
parent 39967262e4
commit 8805cab27c
9 changed files with 2192 additions and 0 deletions

View File

@ -196,6 +196,7 @@ OPTION(BUILD_START "Build the FreeCAD start module" ON)
OPTION(BUILD_TEST "Build the FreeCAD test module" ON)
OPTION(BUILD_WEB "Build the FreeCAD web module" ON)
OPTION(BUILD_VR "Build the FreeCAD Oculus Rift support (need Oculus SDK 4.x or higher)" OFF)
OPTION(BUILD_VTK "Build the FreeCAD VTK support (need VTK 6 or higher)" OFF)
if(MSVC)
OPTION(BUILD_FEM_NETGEN "Build the FreeCAD FEM module with the NETGEN mesher" ON)
@ -752,6 +753,14 @@ endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
#---------------------------------------------------
# -------------------------------- VTK --------------------------------
if(BUILD_VTK)
find_package(VTK REQUIRED)
add_definitions(-DFC_USE_VTK)
include(${VTK_USE_FILE})
endif(BUILD_VTK)
if(BUILD_GUI)
# -------------------------------- OpenGL --------------------------------

View File

@ -115,6 +115,13 @@ if(PYSIDE_INCLUDE_DIR)
)
endif(PYSIDE_INCLUDE_DIR)
if(BUILD_VTK)
set(FreeCADGui_LIBS
${FreeCADGui_LIBS}
${VTK_LIBRARIES}
)
endif(BUILD_VTK)
generate_from_xml(DocumentPy)
generate_from_xml(PythonWorkbenchPy)
generate_from_xml(ViewProviderPy)

1167
src/Gui/CMakeLists.txt.orig Normal file

File diff suppressed because it is too large Load Diff

View File

@ -35,6 +35,7 @@
#include <zipios++/gzipoutputstream.h>
#include "SoFCDB.h"
#include "SoVTKActor.h"
#include "SoFCColorBar.h"
#include "SoFCColorLegend.h"
#include "SoFCColorGradient.h"

312
src/Gui/SoFCDB.cpp.orig Normal file
View File

@ -0,0 +1,312 @@
/***************************************************************************
* Copyright (c) 2005 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <Inventor/actions/SoToVRML2Action.h>
# include <Inventor/VRMLnodes/SoVRMLGroup.h>
# include <Inventor/VRMLnodes/SoVRMLParent.h>
# include <Inventor/SbString.h>
# include <Inventor/nodes/SoGroup.h>
#endif
#include <Base/FileInfo.h>
#include <Base/Stream.h>
#include <zipios++/gzipoutputstream.h>
#include "SoFCDB.h"
#include "SoVTKActor.h"
#include "SoFCColorBar.h"
#include "SoFCColorLegend.h"
#include "SoFCColorGradient.h"
#include "SoFCSelection.h"
#include "SoFCBackgroundGradient.h"
#include "SoFCBoundingBox.h"
#include "SoFCSelection.h"
#include "SoFCUnifiedSelection.h"
#include "SoFCSelectionAction.h"
#include "SoFCInteractiveElement.h"
#include "SoFCUnifiedSelection.h"
#include "SoFCVectorizeSVGAction.h"
#include "SoFCVectorizeU3DAction.h"
#include "SoAxisCrossKit.h"
#include "SoTextLabel.h"
#include "SoNavigationDragger.h"
#include "Inventor/SoDrawingGrid.h"
#include "Inventor/SoAutoZoomTranslation.h"
#include "Inventor/MarkerBitmaps.h"
#include "SoFCCSysDragger.h"
#include "propertyeditor/PropertyItem.h"
#include "NavigationStyle.h"
#include "Flag.h"
#include "SelectionObject.h"
using namespace Gui;
using namespace Gui::Inventor;
using namespace Gui::PropertyEditor;
static SbBool init_done = false;
static SoGroup *storage = nullptr;
SbBool Gui::SoFCDB::isInitialized(void)
{
return init_done;
}
void Gui::SoFCDB::init()
{
SoInteraction ::init();
RotTransDragger ::initClass();
SoGLRenderActionElement ::initClass();
SoFCInteractiveElement ::initClass();
SoGLWidgetElement ::initClass();
SoFCColorBarBase ::initClass();
SoFCColorBar ::initClass();
SoFCColorLegend ::initClass();
SoFCColorGradient ::initClass();
SoFCBackgroundGradient ::initClass();
SoFCBoundingBox ::initClass();
SoFCSelection ::initClass();
SoFCUnifiedSelection ::initClass();
SoFCSelectionAction ::initClass();
SoFCDocumentAction ::initClass();
SoGLWidgetNode ::initClass();
SoFCEnableSelectionAction ::initClass();
SoFCEnableHighlightAction ::initClass();
SoFCSelectionColorAction ::initClass();
SoFCHighlightColorAction ::initClass();
SoFCDocumentObjectAction ::initClass();
SoGLSelectAction ::initClass();
SoVisibleFaceAction ::initClass();
SoBoxSelectionRenderAction ::initClass();
SoFCVectorizeSVGAction ::initClass();
SoFCVectorizeU3DAction ::initClass();
SoHighlightElementAction ::initClass();
SoSelectionElementAction ::initClass();
SoVRMLAction ::initClass();
SoSkipBoundingGroup ::initClass();
SoTextLabel ::initClass();
SoStringLabel ::initClass();
SoFrameLabel ::initClass();
TranslateManip ::initClass();
SoShapeScale ::initClass();
SoAxisCrossKit ::initClass();
SoRegPoint ::initClass();
SoDrawingGrid ::initClass();
SoAutoZoomTranslation ::initClass();
MarkerBitmaps ::initClass();
<<<<<<< d7d347b2d62ec685840e7db1c35863e659148981
SoFCCSysDragger ::initClass();
=======
SoVTKActor ::initClass();
>>>>>>> proof of concept
PropertyItem ::init();
PropertySeparatorItem ::init();
PropertyStringItem ::init();
PropertyFontItem ::init();
PropertyIntegerItem ::init();
PropertyIntegerConstraintItem ::init();
PropertyFloatItem ::init();
PropertyUnitItem ::init();
PropertyFloatConstraintItem ::init();
PropertyUnitConstraintItem ::init();
PropertyAngleItem ::init();
PropertyBoolItem ::init();
PropertyVectorItem ::init();
PropertyVectorDistanceItem ::init();
PropertyMatrixItem ::init();
PropertyPlacementItem ::init();
PropertyEnumItem ::init();
PropertyStringListItem ::init();
PropertyFloatListItem ::init();
PropertyIntegerListItem ::init();
PropertyColorItem ::init();
PropertyMaterialItem ::init();
PropertyMaterialListItem ::init();
PropertyFileItem ::init();
PropertyPathItem ::init();
PropertyTransientFileItem ::init();
PropertyLinkItem ::init();
NavigationStyle ::init();
UserNavigationStyle ::init();
InventorNavigationStyle ::init();
CADNavigationStyle ::init();
BlenderNavigationStyle ::init();
MayaGestureNavigationStyle ::init();
TouchpadNavigationStyle ::init();
GestureNavigationStyle ::init();
OpenCascadeNavigationStyle ::init();
GLGraphicsItem ::init();
GLFlagWindow ::init();
SelectionObject ::init();
qRegisterMetaType<Base::Vector3f>("Base::Vector3f");
qRegisterMetaType<Base::Vector3d>("Base::Vector3d");
qRegisterMetaType<Base::Quantity>("Base::Quantity");
qRegisterMetaType<QList<Base::Quantity> >("Base::QuantityList");
init_done = true;
assert(!storage);
storage = new SoGroup();
storage->ref();
}
void Gui::SoFCDB::finish()
{
// Coin doesn't provide a mechanism to free static members of own data types.
// Hence, we need to define a static method e.g. 'finish()' for all new types
// to invoke the private member function 'atexit_cleanup()'.
SoFCColorBarBase ::finish();
SoFCColorBar ::finish();
SoFCColorLegend ::finish();
SoFCColorGradient ::finish();
SoFCBackgroundGradient ::finish();
SoFCBoundingBox ::finish();
SoFCSelection ::finish();
SoFCSelectionAction ::finish();
SoFCDocumentAction ::finish();
SoFCDocumentObjectAction ::finish();
SoFCEnableSelectionAction ::finish();
SoFCEnableHighlightAction ::finish();
SoFCSelectionColorAction ::finish();
SoFCHighlightColorAction ::finish();
storage->unref();
storage = nullptr;
}
// buffer acrobatics for inventor ****************************************************
static char * buffer;
static size_t buffer_size = 0;
static std::string cReturnString;
static void *
buffer_realloc(void * bufptr, size_t size)
{
buffer = (char *)realloc(bufptr, size);
buffer_size = size;
return buffer;
}
const std::string& Gui::SoFCDB::writeNodesToString(SoNode * root)
{
SoOutput out;
buffer = (char *)malloc(1024);
buffer_size = 1024;
out.setBuffer(buffer, buffer_size, buffer_realloc);
if (root && root->getTypeId().isDerivedFrom(SoVRMLParent::getClassTypeId()))
out.setHeaderString("#VRML V2.0 utf8");
SoWriteAction wa(&out);
wa.apply(root);
cReturnString = buffer;
free(buffer);
return cReturnString;
}
bool Gui::SoFCDB::writeToVRML(SoNode* node, const char* filename, bool binary)
{
SoVRMLAction vrml2;
vrml2.setOverrideMode(true);
vrml2.apply(node);
SoToVRML2Action tovrml2;
tovrml2.apply(node);
SoVRMLGroup* vrmlRoot = tovrml2.getVRML2SceneGraph();
vrmlRoot->setInstancePrefix(SbString("o"));
vrmlRoot->ref();
std::string buffer = SoFCDB::writeNodesToString(vrmlRoot);
vrmlRoot->unref(); // release the memory as soon as possible
// restore old settings
vrml2.setOverrideMode(false);
vrml2.apply(node);
Base::FileInfo fi(filename);
if (binary) {
// We want to write compressed VRML but Coin 2.4.3 doesn't do it even though
// SoOutput::getAvailableCompressionMethods() delivers a string list that
// contains 'GZIP'. setCompression() was called directly after opening the file,
// returned true and no error message appeared but anyway it didn't work.
// Strange is that reading GZIPped VRML files works.
// So, we do the compression on our own.
Base::ofstream str(fi, std::ios::out | std::ios::binary);
zipios::GZIPOutputStream gzip(str);
if (gzip) {
gzip << buffer;
gzip.close();
return true;
}
}
else {
Base::ofstream str(fi, std::ios::out);
if (str) {
str << buffer;
str.close();
return true;
}
}
return false;
}
bool Gui::SoFCDB::writeToFile(SoNode* node, const char* filename, bool binary)
{
bool ret = false;
Base::FileInfo fi(filename);
// Write VRML V2.0
if (fi.hasExtension("wrl") || fi.hasExtension("vrml") || fi.hasExtension("wrz")) {
// If 'wrz' is set then force compression
if (fi.hasExtension("wrz"))
binary = true;
ret = SoFCDB::writeToVRML(node, filename, binary);
}
else if (fi.hasExtension("iv")) {
// Write Inventor in ASCII
std::string buffer = SoFCDB::writeNodesToString(node);
Base::ofstream str(Base::FileInfo(filename), std::ios::out);
if (str) {
str << buffer;
str.close();
ret = true;
}
}
return ret;
}
SoGroup* Gui::SoFCDB::getStorage()
{
assert(storage); //call init first.
return storage;
}

337
src/Gui/SoVTKActor.cpp Normal file
View File

@ -0,0 +1,337 @@
/***************************************************************************
* Copyright (c) 2015 Stefan Tröger <stefantroeger@gmx.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifdef FC_USE_VTK
#include "SoVTKActor.h"
#include "InventorAll.h"
#include <Base/Console.h>
#include <Inventor/SbViewportRegion.h>
#include <vtkMapper.h>
#include <vtkGeometryFilter.h>
#include <vtkProperty.h>
#include <vtkPolyDataMapper.h>
#include <vtkAlgorithmOutput.h>
#include <vtkCellArray.h>
#include <vtkPointData.h>
using namespace Gui;
SO_NODE_SOURCE(SoVTKActor);
void SoVTKActor::initClass()
{
SO_NODE_INIT_CLASS(SoVTKActor, SoSeparator, "VTKActor");
}
SoVTKActor::SoVTKActor() : SoSeparator(), m_mapper(NULL)
{
SO_NODE_CONSTRUCTOR(SoVTKActor);
//create the subnodes which do the visualization work
m_shapeHints = new SoShapeHints();
m_shapeHints->ref();
m_shapeHints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
m_coordinates = new SoCoordinate3();
m_coordinates->ref();
m_materialBinding = new SoMaterialBinding();
m_materialBinding->ref();
m_material = new SoMaterial();
m_material->ref();
m_normalBinding = new SoNormalBinding();
m_normalBinding->ref();
m_normals = new SoNormal();
m_normals->ref();
m_faces = new SoIndexedFaceSet();
m_faces->ref();
m_triangleStrips = new SoIndexedTriangleStripSet();
m_triangleStrips->ref();
m_markers = new SoIndexedMarkerSet();
m_markers->ref();
m_lines = new SoIndexedLineSet();
m_lines->ref();
addChild(m_shapeHints);
addChild(m_materialBinding);
addChild(m_material);
addChild(m_normalBinding);
addChild(m_normals);
addChild(m_coordinates);
addChild(m_markers);
addChild(m_lines);
addChild(m_faces);
addChild(m_triangleStrips);
}
SoVTKActor::~SoVTKActor()
{
}
void SoVTKActor::doAction(SoAction* action)
{
SoNode::doAction(action);
}
void SoVTKActor::setMapper(vtkMapper* m)
{
m_mapper = m;
vtkDataSet *ds;
vtkPolyData *pd;
vtkGeometryFilter *gf = NULL;
vtkPointData *pntData;
vtkPoints *points;
vtkDataArray *normals = NULL;
vtkDataArray *tcoords = NULL;
int i;
vtkProperty *prop;
double *tempd;
vtkCellArray *cells;
vtkIdType npts = 0;
vtkIdType *indx = 0;
float tempf2;
vtkPolyDataMapper *pm;
vtkUnsignedCharArray *colors;
double *p;
unsigned char *c;
vtkTransform *trans;
Base::Console().Message("render SoVTKActor\n");
// see if the actor has a mapper. it could be an assembly
if (m_mapper == NULL)
return;
ds = m_mapper->GetInput();
vtkAlgorithmOutput* pdProducer = 0;
// we really want polydata
if ( ds->GetDataObjectType() != VTK_POLY_DATA ) {
gf = vtkGeometryFilter::New();
gf->SetInputConnection(
m_mapper->GetInputConnection(0, 0));
gf->Update();
pd = gf->GetOutput();
pdProducer = gf->GetOutputPort();
}
else {
m_mapper->GetInputAlgorithm()->Update();
pd = static_cast<vtkPolyData *>(ds);
pdProducer = m_mapper->GetInputConnection(0, 0);
}
pm = vtkPolyDataMapper::New();
pm->SetInputConnection(pdProducer);
pm->SetScalarRange(m_mapper->GetScalarRange());
pm->SetScalarVisibility(m_mapper->GetScalarVisibility());
pm->SetLookupTable(m_mapper->GetLookupTable());
points = pd->GetPoints();
pntData = pd->GetPointData();
normals = pntData->GetNormals();
tcoords = pntData->GetTCoords();
colors = pm->MapScalars(1.0);
// write out point data if any
WritePointData(points, normals, tcoords, colors);
// write out polys if any
if (pd->GetNumberOfPolys() > 0) {
Base::Console().Message("render polys: %i\n", pd->GetNumberOfPolys());
m_faces->coordIndex.startEditing();
int soidx = 0;
cells = pd->GetPolys();
for (cells->InitTraversal(); cells->GetNextCell(npts,indx); ) {
for (i = 0; i < npts; i++) {
m_faces->coordIndex.set1Value(soidx, static_cast<int>(indx[i]));
++soidx;
}
m_faces->coordIndex.set1Value(soidx, -1);
++soidx;
}
m_faces->coordIndex.finishEditing();
}
// write out tstrips if any
if (pd->GetNumberOfStrips() > 0) {
Base::Console().Message("render strips\n");
int soidx = 0;
cells = pd->GetStrips();
m_triangleStrips->coordIndex.startEditing();
for (cells->InitTraversal(); cells->GetNextCell(npts,indx); ) {
for (i = 0; i < npts; i++) {
m_triangleStrips->coordIndex.set1Value(soidx, static_cast<int>(indx[i]));
++soidx;
}
m_triangleStrips->coordIndex.set1Value(soidx, -1);
++soidx;
}
m_triangleStrips->coordIndex.finishEditing();
}
// write out lines if any
if (pd->GetNumberOfLines() > 0) {
Base::Console().Message("render lines: %i\n", pd->GetNumberOfLines());
int soidx = 0;
cells = pd->GetLines();
m_lines->coordIndex.startEditing();
for (cells->InitTraversal(); cells->GetNextCell(npts,indx); ) {
for (i = 0; i < npts; i++) {
m_lines->coordIndex.set1Value(soidx, static_cast<int>(indx[i]));
++soidx;
}
m_lines->coordIndex.set1Value(soidx, -1);
++soidx;
}
m_lines->coordIndex.finishEditing();
}
// write out verts if any
// (more complex because there is no IndexedPointSet)
if (pd->GetNumberOfVerts() > 0){
Base::Console().Message("render verts\n");
int soidx = 0;
cells = pd->GetVerts();
m_markers->coordIndex.startEditing();
for (cells->InitTraversal(); cells->GetNextCell(npts,indx); ) {
for (i = 0; i < npts; i++) {
m_markers->coordIndex.set1Value(soidx, static_cast<int>(indx[i]));
++soidx;
}
m_markers->coordIndex.set1Value(soidx, -1);
++soidx;
}
m_markers->coordIndex.finishEditing();
}
if (gf)
gf->Delete();
pm->Delete();
}
vtkMapper* SoVTKActor::getMapper()
{
return m_mapper;
}
/*
void SoVTKActor::GLRender(SoGLRenderAction *action)
{
}*/
void SoVTKActor::WritePointData(vtkPoints *points, vtkDataArray *normals,
vtkDataArray *tcoords,
vtkUnsignedCharArray *colors)
{
double *p;
int i;
unsigned char *c;
if(!points)
return;
Base::Console().Message("render points: %i", points->GetNumberOfPoints());
if(colors)
Base::Console().Message(", colors: %i", colors->GetNumberOfTuples());
Base::Console().Message("\n");
m_coordinates->point.startEditing();
for (i = 0; i < points->GetNumberOfPoints(); i++) {
p = points->GetPoint(i);
m_coordinates->point.set1Value(i, p[0], p[1], p[2]);
}
m_coordinates->point.finishEditing();
// write out the point nrmal data
if (normals) {
Base::Console().Message("Write normals: %i\n", normals->GetNumberOfTuples());
m_normals->vector.startEditing();
for (i = 0; i < normals->GetNumberOfTuples(); i++) {
p = normals->GetTuple(i);
m_normals->vector.set1Value(i, SbVec3f(p[0], p[1], p[2]));
}
m_normals->vector.finishEditing();
m_normalBinding->value = SoNormalBinding::PER_VERTEX_INDEXED;
m_normalBinding->value.touch();
}
/*
// write out the point data
if (tcoords)
{
fprintf(fp,"%sTextureCoordinateBinding {\n",indent);
VTK_INDENT_MORE;
fprintf(fp,"%svalue PER_VERTEX_INDEXED\n",indent);
VTK_INDENT_LESS;
fprintf(fp,"%s}\n",indent);
fprintf(fp,"%sTextureCoordinate2 {\n", indent);
VTK_INDENT_MORE;
fprintf(fp,"%spoint [\n", indent);
VTK_INDENT_MORE;
for (i = 0; i < tcoords->GetNumberOfTuples(); i++)
{
p = tcoords->GetTuple(i);
fprintf (fp,"%s%g %g,\n", indent, p[0], p[1]);
}
fprintf(fp,"%s]\n", indent);
VTK_INDENT_LESS;
fprintf(fp,"%s}\n", indent);
VTK_INDENT_LESS;
}*/
// write out the point data
if (colors) {
m_material->diffuseColor.startEditing();
m_material->transparency.startEditing();
for (i = 0; i < colors->GetNumberOfTuples(); i++) {
c = colors->GetPointer(4*i);
m_material->diffuseColor.set1Value(i,static_cast<unsigned long>(c[3]),
static_cast<unsigned long>(c[2]),
static_cast<unsigned long>(c[1]));
m_material->transparency.set1Value(i, static_cast<unsigned long>(c[0]));
}
m_material->diffuseColor.finishEditing();
m_material->transparency.finishEditing();
m_materialBinding->value = SoMaterialBinding::PER_VERTEX_INDEXED;
m_materialBinding->touch();
}
}
#endif //FC_USE_VTK

97
src/Gui/SoVTKActor.h Normal file
View File

@ -0,0 +1,97 @@
/***************************************************************************
* Copyright (c) 2015 Stefan Tröger <stefantroeger@gmx.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef GUI_SOVTKACTOR_H
#define GUI_SOVTKACTOR_H
#ifdef FC_USE_VTK
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoCoordinate3.h>
#include <Inventor/nodes/SoIndexedMarkerSet.h>
#include <Inventor/nodes/SoIndexedLineSet.h>
#include <Inventor/nodes/SoIndexedFaceSet.h>
#include <Inventor/nodes/SoIndexedTriangleStripSet.h>
#include <Inventor/nodes/SoPackedColor.h>
#include <Inventor/nodes/SoMaterialBinding.h>
#include <Inventor/nodes/SoShapeHints.h>
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoNormalBinding.h>
#include <Inventor/nodes/SoNormal.h>
class vtkPoints;
class vtkDataArray;
class vtkUnsignedCharArray;
class vtkMapper;
class SoGLCoordinateElement;
class SoTextureCoordinateBundle;
namespace Gui {
class GuiExport SoVTKActor : public SoSeparator {
SO_NODE_HEADER(SoVTKActor);
public:
static void initClass();
SoVTKActor();
//vtkActor functions
static SoVTKActor *New();
void setMapper(vtkMapper* m);
vtkMapper* getMapper();
protected:
virtual ~SoVTKActor();
//SoNode functions
/*
virtual void GLRender(SoGLRenderAction *action);
virtual void GLRenderBelowPath(SoGLRenderAction* action);
virtual void GLRenderInPath(SoGLRenderAction* action);
virtual void GLRenderOffPath(SoGLRenderAction* action);*/
virtual void doAction(SoAction* action);
void WritePointData(vtkPoints *points, vtkDataArray *normals,
vtkDataArray *tcoords,
vtkUnsignedCharArray *colors);
vtkMapper* m_mapper;
SoCoordinate3* m_coordinates;
SoIndexedMarkerSet* m_markers;
SoIndexedLineSet* m_lines;
SoIndexedFaceSet* m_faces;
SoIndexedTriangleStripSet* m_triangleStrips;
SoMaterialBinding* m_materialBinding;
SoShapeHints* m_shapeHints;
SoMaterial* m_material;
SoNormalBinding* m_normalBinding;
SoNormal* m_normals;
};
} // namespace PartGui
#endif // FC_USE_VTK
#endif // GUI_SOVTKACTOR_H

View File

@ -129,6 +129,24 @@
#include "WinNativeGestureRecognizers.h"
#include "Document.h"
#include "SoVTKActor.h"
#include "vtkDataSetSurfaceFilter.h"
#include "vtkGeometryFilter.h"
#include "vtkLookupTable.h"
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkContourFilter.h"
#include "vtkCubeSource.h"
#include "vtkPlane.h"
#include "vtkCutter.h"
#include "vtkHedgeHog.h"
#include "vtkGlyph3D.h"
#include "vtkArrowSource.h"
#include "vtkPointSource.h"
#include "vtkRungeKutta4.h"
#include "vtkStreamTracer.h"
#include "vtkPointLocator.h"
//#define FC_LOGGING_CB
using namespace Gui;
@ -527,6 +545,241 @@ 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()

View File

@ -39,6 +39,10 @@
#include <Gui/Selection.h>
#include <vtkDataSetReader.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
class SoTranslation;
class SoTransform;
class SoText2;
@ -431,6 +435,11 @@ private:
friend class NavigationStyle;
friend class GLPainter;
friend class ViewerEventFilter;
//vtk test
vtkSmartPointer<vtkDataSetReader> source;
vtkSmartPointer<vtkPolyDataMapper> mapper;
};
} // namespace Gui