diff --git a/Base/CMakeLists.txt b/Base/CMakeLists.txt index 8c648d33eae8b3e5e83d36537d14cde2dfd4671c..af1ca87ef2a211bc84a4dbd836a4a4750ae9ff8a 100644 --- a/Base/CMakeLists.txt +++ b/Base/CMakeLists.txt @@ -7,7 +7,7 @@ set( SOURCES TreeModel.cpp ColorPickerPushButton.cpp TreeModelIterator.cpp - modeltest.cpp + # modeltest.cpp # Not needed CheckboxDelegate.cpp QValueTooltipSlider.cpp ) @@ -17,7 +17,7 @@ set( MOC_HEADERS RecentFiles.h TreeModel.h ColorPickerPushButton.h - modeltest.h + # modeltest.h # Not needed CheckboxDelegate.h QValueTooltipSlider.h ) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bb4b62bf78ac242a761589294c2c74f216df4dd..782ced848cf52d9bbc85eff7560e8c4ffdd62800 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,3 @@ - -# Visual Studio settings -IF (MSVC) - ADD_DEFINITIONS( - -D/MP # For multicore compiling - ) -ENDIF (MSVC) - - IF (NOT VTK_FOUND) MESSAGE(FATAL_ERROR "Error: VTK was not found but is needed for the GUI. Aborting...") ENDIF (NOT VTK_FOUND) @@ -15,6 +6,9 @@ INCLUDE( ${VTK_USE_FILE} ) # Find libgeotiff FIND_PACKAGE( LibTiff ) FIND_PACKAGE( LibGeoTiff ) +IF(libgeotiff_FOUND) + ADD_DEFINITIONS(-Dlibgeotiff_FOUND) +ENDIF() # libgeotiff_FOUND SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /ZI /Od /Ob0") diff --git a/DataView/MshEditDialog.cpp b/DataView/MshEditDialog.cpp index b8e65bc7e07a46209d10df9a78f78ada7513ed87..70e5d1b77d4240f603096e062b0054cc5721ac7e 100644 --- a/DataView/MshEditDialog.cpp +++ b/DataView/MshEditDialog.cpp @@ -47,9 +47,10 @@ MshEditDialog::MshEditDialog(const MeshLib::CFEMesh* mesh, QDialog* parent) _noDataDeleteBox = new QCheckBox("Remove mesh nodes at NoData values"); _noDataDeleteBox->setChecked(false); + _noDataDeleteBox->setEnabled(false); if (nLayers==1) { - _noDataDeleteBox->setChecked(true); + _noDataDeleteBox->setEnabled(true); this->gridLayoutLayerMapping->addWidget(_noDataDeleteBox, 2, 1); } diff --git a/DataView/MshLayerMapper.cpp b/DataView/MshLayerMapper.cpp index 040464fcdf3c2958128576f30e4cb879b956ed11..577c70a1050477886cdcfc9ee2cd05a081f36fe4 100644 --- a/DataView/MshLayerMapper.cpp +++ b/DataView/MshLayerMapper.cpp @@ -35,13 +35,10 @@ MeshLib::CFEMesh* MshLayerMapper::CreateLayers(const MeshLib::CFEMesh* mesh, siz { // add nodes for new layer size_t node_offset ( nNodes*layer_id ); - double z_offset ( layer_id*thickness ); +// TF unused variable double z_offset ( layer_id*thickness ); for (size_t i=0; i<nNodes; i++) { - MeshLib::CNode* node( new MeshLib::CNode( node_offset + i ) ); - double coords[3] = { mesh->nod_vector[i]->X(), mesh->nod_vector[i]->Y(), mesh->nod_vector[i]->Z()-z_offset }; - node->SetCoordinates(coords); - new_mesh->nod_vector.push_back(node); + new_mesh->nod_vector.push_back(new MeshLib::CNode( node_offset + i, mesh->nod_vector[i]->getData())); } if (layer_id>0) // starting with the 2nd layer prism (or hex) elements can be created @@ -132,8 +129,8 @@ MeshLib::CFEMesh* MshLayerMapper::LayerMapping(const MeshLib::CFEMesh* msh, cons for(size_t i=firstNode; i<lastNode; i++) { - size_t xPos (static_cast<size_t>(floor((msh->nod_vector[i]->X() - xDim.first) / delta))); - size_t yPos (static_cast<size_t>(floor((msh->nod_vector[i]->Y() - yDim.first) / delta))); + size_t xPos (static_cast<size_t>(floor((msh->nod_vector[i]->getData()[0] - xDim.first) / delta))); + size_t yPos (static_cast<size_t>(floor((msh->nod_vector[i]->getData()[1] - yDim.first) / delta))); locX[0] = xDim.first+xPos*delta; locY[0] = yDim.first+yPos*delta; @@ -161,8 +158,9 @@ MeshLib::CFEMesh* MshLayerMapper::LayerMapping(const MeshLib::CFEMesh* msh, cons { // Interpolate double ome[4]; - double xi = 2.0*(msh->nod_vector[i]->X()-0.5*(locX[0]+locX[1]))/delta; - double eta = 2.0*(msh->nod_vector[i]->Y()-0.5*(locY[1]+locY[2]))/delta; + double const*const coords (msh->nod_vector[i]->getData()); + double xi = 2.0*(coords[0]-0.5*(locX[0]+locX[1]))/delta; + double eta = 2.0*(coords[1]-0.5*(locY[1]+locY[2]))/delta; MPhi2D(ome, xi, eta); double z(0.0); @@ -179,7 +177,7 @@ MeshLib::CFEMesh* MshLayerMapper::LayerMapping(const MeshLib::CFEMesh* msh, cons } } - if ((nLayers == 1) && removeNoDataValues) + if ((nLayers == 1) && removeNoDataValues) { if (noData_nodes.size() < (new_mesh->nod_vector.size()-2)) { @@ -217,19 +215,21 @@ MeshLib::CFEMesh* MshLayerMapper::LayerMapping(const MeshLib::CFEMesh* msh, cons // KR, based on code by WW (Note: this method has not been tested yet and will probably fail miserably!) bool MshLayerMapper::meshFitsImage(const MeshLib::CFEMesh* msh, const std::pair<double, double> &xDim, const std::pair<double, double> &yDim) { - double xMin(msh->nod_vector[0]->X()); - double yMin(msh->nod_vector[0]->Y()); - double xMax(msh->nod_vector[0]->X()); - double yMax(msh->nod_vector[0]->Y()); + double const* pnt (msh->nod_vector[0]->getData()); + double xMin(pnt[0]); + double yMin(pnt[1]); + double xMax(pnt[0]); + double yMax(pnt[1]); size_t nNodes = msh->nod_vector.size(); for (size_t i=1; i<nNodes; i++) { - if (xMin > msh->nod_vector[i]->X()) xMin = msh->nod_vector[i]->X(); - else if (xMax < msh->nod_vector[i]->X()) xMax = msh->nod_vector[i]->X(); + pnt = msh->nod_vector[i]->getData(); + if (xMin > pnt[0]) xMin = pnt[0]; + else if (xMax < pnt[0]) xMax = pnt[0]; - if (yMin > msh->nod_vector[i]->Y()) yMin = msh->nod_vector[i]->Y(); - else if (yMax < msh->nod_vector[i]->Y()) yMax = msh->nod_vector[i]->Y(); + if (yMin > pnt[1]) yMin = pnt[1]; + else if (yMax < pnt[1]) yMax = pnt[1]; } if (xMin < xDim.first || xMax > xDim.second || yMin < yDim.first || yMax > yDim.second) @@ -278,18 +278,20 @@ void MshLayerMapper::CheckLayerMapping(MeshLib::CFEMesh* mesh, const size_t nLay if (k==0) { tmp_connected_nodes.clear(); - for (size_t j=0; j<tNode->connected_nodes.size(); j++) - tmp_connected_nodes.push_back(tNode->connected_nodes[j]); + std::vector<size_t> const& connected_nodes (tNode->getConnectedNodes()); + const size_t n_connected_nodes (connected_nodes.size()); + for (size_t j=0; j<n_connected_nodes; j++) + tmp_connected_nodes.push_back(connected_nodes[j]); } - tNode->SetZ(bNode->Z()); // z coordinate changed to layer above - tNode->connected_nodes.clear(); + tNode->SetZ(bNode->getData()[2]); // z coordinate changed to layer above + tNode->getConnectedNodes().clear(); for (int j=k; j>=0; j--) //WW/YW. 23.01.2009 { MeshLib::CNode* nNode = mesh->nod_vector[j*nNodesPerLayer+i]; if (nNode->GetMark()) { - tNode->connected_nodes.push_back(nNode->GetIndex()); + tNode->getConnectedNodes().push_back(nNode->GetIndex()); break; } } @@ -303,21 +305,21 @@ void MshLayerMapper::CheckLayerMapping(MeshLib::CFEMesh* mesh, const size_t nLay MeshLib::CNode* bNode = mesh->nod_vector[nNodesPerLayer+i]; bNode->SetMark(true); - bNode->connected_nodes.clear(); + bNode->getConnectedNodes().clear(); for (size_t j=0; j<tmp_connected_nodes.size(); j++) - bNode->connected_nodes.push_back(tmp_connected_nodes[j]); + bNode->getConnectedNodes().push_back(tmp_connected_nodes[j]); MeshLib::CNode* tNode = mesh->nod_vector[(nLayers-1)*nNodesPerLayer+i]; tNode->SetMark(false); - bNode->SetZ(tNode->Z()); + bNode->SetZ(tNode->getData()[2]); bNode->SetBoundaryType('1'); // for (size_t k=1; k<nLayers; k++) { tNode = mesh->nod_vector[(k+1)*nNodesPerLayer+i]; tNode->SetZ(ref_dep); - tNode->connected_nodes.clear(); - tNode->connected_nodes.push_back(bNode->GetIndex()); + tNode->getConnectedNodes().clear(); + tNode->getConnectedNodes().push_back(bNode->GetIndex()); } } @@ -335,8 +337,8 @@ void MshLayerMapper::CheckLayerMapping(MeshLib::CFEMesh* mesh, const size_t nLay flat = 0; for (size_t k=0; k<3;k++) //skip element when one node is marked ref_dep { - if ( fabs(elem->GetNode(k)->Z() +ref_dep)<std::numeric_limits<double>::min() || - fabs(elem->GetNode(k+3)->Z()+ref_dep)<std::numeric_limits<double>::min() ) + if ( fabs(elem->GetNode(k)->getData()[2] +ref_dep)<std::numeric_limits<double>::min() || + fabs(elem->GetNode(k+3)->getData()[2]+ref_dep)<std::numeric_limits<double>::min() ) { flat = 1; elem->SetMark(false); @@ -348,7 +350,7 @@ void MshLayerMapper::CheckLayerMapping(MeshLib::CFEMesh* mesh, const size_t nLay // If all nodes are okay, check if two z-values are identical for (size_t k=0; k<3;k++) { - if(fabs(elem->GetNode(k+3)->Z()-elem->GetNode(k)->Z()) < std::numeric_limits<double>::min()) + if(fabs(elem->GetNode(k+3)->getData()[2]-elem->GetNode(k)->getData()[2]) < std::numeric_limits<double>::min()) false_node_idx.push_back(k); } @@ -487,7 +489,7 @@ void MshLayerMapper::CheckLayerMapping(MeshLib::CFEMesh* mesh, const size_t nLay { node->SetIndex(counter); node->getConnectedElementIDs().clear(); - node->connected_nodes.clear(); + node->getConnectedNodes().clear(); counter++; } else diff --git a/DataView/OGSRaster.cpp b/DataView/OGSRaster.cpp index a481e5b4d4c184e5c7ad2b3d29da4bd1d45f2e15..28ad7e10064c45aa57b6fe62ba5d9d4512136de5 100644 --- a/DataView/OGSRaster.cpp +++ b/DataView/OGSRaster.cpp @@ -16,7 +16,7 @@ #include "StringTools.h" #include "OGSError.h" -#ifdef libgeotiff_FOUND +#ifdef libgeotiff_FOUND #include "geo_tiffp.h" #include "xtiffio.h" #endif @@ -35,14 +35,14 @@ bool OGSRaster::loadImage(const QString &fileName, QImage &raster, QPointF &orig if (mirrorX) raster = raster.transformed(QTransform(1, 0, 0, -1, 0, 0), Qt::FastTransformation); } -#ifdef libgeotiff_FOUND +#ifdef libgeotiff_FOUND else if (fileInfo.suffix().toLower() == "tif") { if (!loadImageFromTIFF(fileName, raster, origin, scalingFactor)) return false; if (!mirrorX) raster = raster.transformed(QTransform(1, 0, 0, -1, 0, 0), Qt::FastTransformation); } -#endif +#endif else { if (!loadImageFromFile(fileName, raster)) return false; @@ -65,7 +65,7 @@ bool OGSRaster::loadImageFromASC(const QString &fileName, QImage &raster, QPoint if (readASCHeader(header, in)) { int index=0, gVal; - double value, minVal=pow(2.0,16), maxVal=0; + double value, minVal=65536, maxVal=0; double *pixVal (new double[header.ncols * header.nrows]); QImage img(header.ncols, header.nrows, QImage::Format_ARGB32); @@ -191,7 +191,7 @@ double* OGSRaster::loadDataFromASC(const QString &fileName, double &x0, double & return NULL; } -#ifdef libgeotiff_FOUND +#ifdef libgeotiff_FOUND bool OGSRaster::loadImageFromTIFF(const QString &fileName, QImage &raster, QPointF &origin, double &cellsize) { TIFF* tiff = XTIFFOpen(fileName.toStdString().c_str(), "r"); @@ -346,7 +346,7 @@ int OGSRaster::getMaxValue(const QImage &raster) int OGSRaster::getMinValue(const QImage &raster) { - int value, minVal = static_cast <int> (pow(2.0,16)); + int value, minVal = 65536; for (int i=0; i<raster.width(); i++) { for (int j=0; j<raster.height(); j++) diff --git a/DataView/OGSRaster.h b/DataView/OGSRaster.h index 4605afbc5897c729157f278299616df0d97dd749..58a1d38d0a0f9aecc26a3850290e21be7b133c45 100644 --- a/DataView/OGSRaster.h +++ b/DataView/OGSRaster.h @@ -7,7 +7,6 @@ #define OGSRASTER_H #include <fstream> -#include "Configure.h" class QImage; class QPointF; diff --git a/DataView/StationTreeView.cpp b/DataView/StationTreeView.cpp index ca0204256e9ab629ce9faecd7dba2fc6d097e51a..ec3b8568c770076e0026c9b05f3eedecfaf94e6e 100644 --- a/DataView/StationTreeView.cpp +++ b/DataView/StationTreeView.cpp @@ -7,7 +7,6 @@ #include <QFileDialog> #include <QMenu> -#include "Configure.h" #include "Station.h" #include "StationIO.h" #include "GMSInterface.h" diff --git a/Gui/main.cpp b/Gui/main.cpp index 56d3dacc67768e7b4a000667aec4c336df24e082..08110b276445a80ef78af9a9f65fdae8a886068e 100644 --- a/Gui/main.cpp +++ b/Gui/main.cpp @@ -1,6 +1,6 @@ +#include "Configure.h" #include <QtGui/QApplication> #include "mainwindow.h" -#include "Configure.h" #ifdef OGS_USE_OPENSG #include <OpenSG/OSGBaseFunctions.h> #endif diff --git a/Gui/mainwindow.cpp b/Gui/mainwindow.cpp index 47d018697fdaa7ab4f274b0ead1061d48c6784bc..e6ed70bad77fcd36519ca6ec433fcad12b204ba6 100644 --- a/Gui/mainwindow.cpp +++ b/Gui/mainwindow.cpp @@ -3,7 +3,7 @@ * 4/11/2009 LB Initial implementation * */ - +#include "Configure.h" #include "mainwindow.h" // models @@ -47,6 +47,7 @@ #include "rf_ic_new.h" #include "wait.h" #include "MathIO/CRSIO.h" +#include "Raster.h" // FileIO includes #include "OGSIOVer4.h" @@ -54,11 +55,12 @@ #include "PetrelInterface.h" #include "GocadInterface.h" #include "XMLInterface.h" -#include "GMSHInterface.h" +#include "MeshIO/GMSHInterface.h" #include "GMSInterface.h" #include "NetCDFInterface.h" //YW 07.2010 #include "GeoIO/Gmsh2GeoIO.h" #include "FEFLOWInterface.h" +#include "MeshIO/TetGenInterface.h" #include "StringTools.h" @@ -77,13 +79,13 @@ // VTK includes #include <vtkVRMLExporter.h> #include <vtkOBJExporter.h> +#include <vtkRenderer.h> #ifdef OGS_USE_OPENSG #include <OpenSG/OSGSceneFileHandler.h> #include <OpenSG/OSGCoredNodePtr.h> #include <OpenSG/OSGGroup.h> -#include "vtkOsgActor.h" -#include "OsgWidget.h" +#include "vtkOsgConverter.h" #endif #ifdef OGS_USE_VRPN @@ -116,15 +118,7 @@ MainWindow::MainWindow(QWidget *parent /* = 0*/) conditionTabWidget->treeView->setModel(_conditionModel); // vtk visualization pipeline -#ifdef OGS_USE_OPENSG - OsgWidget* osgWidget = new OsgWidget(this, 0, Qt::Window); - //osgWidget->show(); - osgWidget->sceneManager()->setRoot(makeCoredNode<OSG::Group>()); - osgWidget->sceneManager()->showAll(); - _vtkVisPipeline = new VtkVisPipeline(visualizationWidget->renderer(), osgWidget->sceneManager()); -#else // OGS_USE_OPENSG _vtkVisPipeline = new VtkVisPipeline(visualizationWidget->renderer()); -#endif // OGS_USE_OPENSG // station model connects connect(stationTabWidget->treeView, @@ -683,6 +677,8 @@ void MainWindow::about() QMenu* MainWindow::createImportFilesMenu() { QMenu* importFiles = new QMenu("&Import Files"); + QAction* feflowFiles = importFiles->addAction("&FEFLOW Files..."); + connect(feflowFiles, SIGNAL(triggered()), this, SLOT(importFeflow())); QAction* gmsFiles = importFiles->addAction("G&MS Files..."); connect(gmsFiles, SIGNAL(triggered()), this, SLOT(importGMS())); QAction* gocadFiles = importFiles->addAction("&Gocad Files..."); @@ -703,8 +699,6 @@ QMenu* MainWindow::createImportFilesMenu() #endif QAction* vtkFiles = importFiles->addAction("&VTK Files..."); connect( vtkFiles, SIGNAL(triggered()), this, SLOT(importVtk()) ); - QAction* feflowFiles = importFiles->addAction("&FEFLOW Files..."); - connect( feflowFiles, SIGNAL(triggered()), this, SLOT(importFeflow()) ); return importFiles; } @@ -1025,7 +1019,7 @@ void MainWindow::callGMSH(std::vector<std::string> const & selectedGeometries, system(gmsh_command.c_str()); this->loadFile(fileName.left(fileName.length()-3).append("msh")); } else { - OGSError::box("Error executing command", "Error"); + OGSError::box("Error executing command gmsh - no command processor available", "Error"); } if (delete_geo_file) { // delete file @@ -1109,6 +1103,147 @@ void MainWindow::showVisalizationPrefsDialog() void MainWindow::FEMTestStart() { + // *** begin test TetGen read mesh + const std::string path ("/home/fischeth/Desktop/data/Ketzin/PSglobal/Tom/MSH/"); + std::string mesh_name ("ClosedSurface"); + std::string fname_nodes(path+mesh_name+".1.node"); + std::string fname_elements(path+mesh_name+".1.ele"); + + FileIO::TetGenInterface tetgen; + MeshLib::CFEMesh *mesh (tetgen.readTetGenMesh (fname_nodes, fname_elements)); + + if (mesh) + _meshModels->addMesh(mesh, mesh_name); + else + OGSError::box("Failed to load TetGen mesh file."); + + // *** end test TetGen read mesh + +// // *** begin creating closed surface mesh +// { +// std::string path("/home/fischeth/Desktop/data/Ketzin/PSglobal/Tom/"); +// std::string fname(path+"ClosedSurface.geo"); +// FileIO::GMSHInterface gmsh_io(fname); +// +// std::vector<std::string> geometries; +// double param4(0); +// +// // all geos for top surface +// geometries.push_back("Boreholes Ketzin Top"); +// geometries.push_back("CoarseGridPointsAsStationsTop"); +// geometries.push_back("MiddleGridPointsAsStationsTop"); +// geometries.push_back("FineGridPointsAsStationsTop"); +// geometries.push_back("KetzinPolygonTop"); +// gmsh_io.writeAllDataToGMSHInputFile(*_geoModels, +// geometries, param4); +// +// geometries.clear(); +// // all geos for bottom surface +// geometries.push_back("Boreholes Ketzin Bottom"); +// geometries.push_back("CoarseGridPointsAsStationsBottom"); +// geometries.push_back("MiddleGridPointsAsStationsBottom"); +// geometries.push_back("FineGridPointsAsStationsBottom"); +// geometries.push_back("KetzinPolygonBottom"); +// +// gmsh_io.writeAllDataToGMSHInputFile(*_geoModels, +// geometries, param4); +// +// geometries.clear(); +// geometries.push_back("KetzinPolygonNorth"); +// gmsh_io.writeAllDataToGMSHInputFile(*_geoModels, +// geometries, param4); +// geometries.clear(); +// geometries.push_back("KetzinPolygonWest"); +// gmsh_io.writeAllDataToGMSHInputFile(*_geoModels, +// geometries, param4); +// geometries.clear(); +// geometries.push_back("KetzinPolygonSouth"); +// gmsh_io.writeAllDataToGMSHInputFile(*_geoModels, +// geometries, param4); +// geometries.clear(); +// geometries.push_back("KetzinPolygonEast"); +// gmsh_io.writeAllDataToGMSHInputFile(*_geoModels, +// geometries, param4); +// } +// // *** end creating closed surface mesh + +// // *** begin assign z values +// { +// // get the surface +// std::vector<std::string> geo_names; +// _geoModels->getGeometryNames (geo_names); +// std::vector<GEOLIB::Surface*> const* sfcs (_geoModels->getSurfaceVec(geo_names[0])); +// GEOLIB::Surface const* sfc ((*sfcs)[5]); +// const size_t n_triangles (sfc->getNTriangles()); +// size_t k; +// +// std::vector<GEOLIB::Point*> const* pnts (_geoModels->getPointVec(geo_names[1])); +// +// // write Points (inclusive z values) to file +// std::ofstream out ("RasterPointsBottom.stn"); +// if (out) { +// // data +// for (size_t n(0); n<pnts->size(); n++) { +// // search triangle the point is inside +// const double test_pnt[3] = { (*(*pnts)[n])[0], (*(*pnts)[n])[1], 0}; +// for (k=0; k<n_triangles; k++) { +// GEOLIB::Triangle const * const tri ((*sfc)[k]); +// if (tri->containsPoint2D(test_pnt)) { +// // compute coefficients c0, c1, c2 for the plane f(x,y) = c0 x + c1 y + c2 +// double c[3]; +// GEOLIB::getPlaneCoefficients(*tri, c); +// const double zval (c[0] * test_pnt[0] + c[1] * test_pnt[1] + c[2]); +// out << " <station x=\"" << test_pnt[0] << "\" y=\"" << test_pnt[1] << "\" z=\"" << zval << "\" id=\"" << n << "\">" << std::endl; +// out << " <name>" << n << "</name>" << std::endl; +// out << " </station>" << std::endl; +// break; +// } +// } +// if (k==n_triangles) { +// out << n << " " << test_pnt[0] << " " << test_pnt[1] << " -9999" << std::endl; +// } +// } +// out.close(); +// } +// } +// // *** end assign z values + +// // *** begin create raster test +// { +// // get the surface +// std::vector<std::string> geo_names; +// _geoModels->getGeometryNames (geo_names); +// std::vector<GEOLIB::Surface*> const* sfcs (_geoModels->getSurfaceVec(geo_names[0])); +// GEOLIB::Surface const* sfc ((*sfcs)[4]); +// +// double cell_size(50); +// double no_data_val(-9999); +// GEOLIB::Raster my_raster (cell_size, no_data_val); +// size_t n_rows(0), n_cols(0); +// double *raster (my_raster.getRasterFromSurface(*sfc, n_rows, n_cols)); +// // write raster to testfile +// std::ofstream out ("RasterTop-50m-New.asc"); +// if (out) { +// // write header +// out << "ncols\t" << n_cols << std::endl; +// out << "nrows\t" << n_rows << std::endl; +// out << "xllcorner\t" << (sfc->getAABB().getMinPoint())[0] - 0.5 * cell_size << std::endl; +// out << "yllcorner\t" << (sfc->getAABB().getMinPoint())[1] - 0.5 * cell_size << std::endl; +// out << "cellsize\t" << cell_size << std::endl; +// out << "NODATA_value\t" << no_data_val << std::endl; +// // data +// for (size_t r(0); r<n_rows; r++) { +// for (size_t c(0); c<n_cols-1; c++) { +// out << raster[r*n_cols+c] << " "; +// } +// out << raster[(r+1)*n_cols-1] << std::endl; +// } +// out.close(); +// } +// delete [] raster; +// } +// // *** end create raster test + // // *** begin test CFEMesh::GetNODOnSFC () // { // // get the surface @@ -1422,13 +1557,13 @@ void MainWindow::on_actionExportOpenSG_triggered(bool checked /*= false*/) while(*it) { VtkVisPipelineItem* item = static_cast<VtkVisPipelineItem*>(*it); - vtkOsgActor* actor = static_cast<vtkOsgActor*>(item->actor()); - actor->SetVerbose(true); - actor->UpdateOsg(); - beginEditCP(root); - root->addChild(actor->GetOsgRoot()); - endEditCP(root); - actor->ClearOsg(); + vtkOsgConverter converter(static_cast<vtkActor*>(item->actor())); + if(converter.WriteAnActor()) + { + beginEditCP(root); + root->addChild(converter.GetOsgNode()); + endEditCP(root); + } ++it; } diff --git a/Gui/mainwindow.h b/Gui/mainwindow.h index 5c45a80d1b154803d81c7f6768ffd82b555a2650..bc5573a50ba6e8932398cbe3c2ecf0a77110fce3 100644 --- a/Gui/mainwindow.h +++ b/Gui/mainwindow.h @@ -8,7 +8,6 @@ #define MAINWINDOW_H #include "ui_mainwindow.h" -#include "Configure.h" #include "FileFinder.h" #include "ProjectData.h" diff --git a/OpenSG/CMakeLists.txt b/OpenSG/CMakeLists.txt index 10eb206bcdda20dbdf7abb83830197e1ffe29206..285f1faa2ecc11d518629f6877036b303ea251d5 100644 --- a/OpenSG/CMakeLists.txt +++ b/OpenSG/CMakeLists.txt @@ -3,51 +3,23 @@ ### Source files ### SET( SOURCES - vtkOsgActor.cpp - OsgWidget.cpp + vtkOsgConverter.cpp ) -### Moc header files ### -SET( MOC_HEADERS - OsgWidget.h -) - -### UI files ### -#SET( UIS -# widget.ui -#) - ### Header files ### SET( HEADERS - vtkOsgActor.h + vtkOsgConverter.h ) -### Qt precompiler ### -#QT4_WRAP_UI( UI_HEADERS ${UIS} ) -Qt4_WRAP_CPP( MOC_SOURCES ${MOC_HEADERS} ) - ### Include directories ### INCLUDE_DIRECTORIES( . - ${CMAKE_BINARY_DIR}/. ) -# Put moc files in a project folder -#SOURCE_GROUP("UI Files" REGULAR_EXPRESSION "\w*\.ui") -#SOURCE_GROUP("Moc Files" REGULAR_EXPRESSION "moc_.*") - ### Create the library ### ADD_LIBRARY( OgsOpenSG STATIC ${SOURCES} ${HEADERS} - ${MOC_HEADERS} - ${MOC_SOURCES} - #${UIS} -) - -### Link other libraries ### -TARGET_LINK_LIBRARIES( OgsOpenSG - ${QT_LIBRARIES} ) USE_OPENSG(OgsOpenSG) \ No newline at end of file diff --git a/OpenSG/OsgWidget.cpp b/OpenSG/OsgWidget.cpp deleted file mode 100644 index faa7ce616debbd4b99e59ce02d6429e8ccf2e8a1..0000000000000000000000000000000000000000 --- a/OpenSG/OsgWidget.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/** - * \file OsgWidget.cpp - * 24/08/2010 LB Initial implementation - * - * Implementation of OsgWidget class - */ - -// ** INCLUDES ** -#include "OsgWidget.h" - -OsgWidget::OsgWidget (QWidget * parent, const QGLWidget *shareWidget, Qt::WindowFlags f) -:QGLWidget(parent, shareWidget, f) -{ - _timer = NULL; - _passiveWin = OSG::PassiveWindow::create(); - _mgr = new OSG::SimpleSceneManager(); - _mgr->setWindow(_passiveWin); -} - -OsgWidget::OsgWidget (QGLContext *context, QWidget *parent, const QGLWidget *shareWidget, Qt::WindowFlags f) -:QGLWidget(context, parent, shareWidget, f) -{ - _timer = NULL; - _passiveWin = OSG::PassiveWindow::create(); - _mgr = new OSG::SimpleSceneManager(); - _mgr->setWindow(_passiveWin); -} - -OsgWidget::OsgWidget (const QGLFormat &format, QWidget *parent, const QGLWidget *shareWidget, Qt::WindowFlags f) -:QGLWidget(format, parent, shareWidget, f) -{ - _timer = NULL; - _passiveWin = OSG::PassiveWindow::create(); - _mgr = new OSG::SimpleSceneManager(); - _mgr->setWindow(_passiveWin); -} - -OsgWidget::~OsgWidget() -{ - delete _mgr; -} - -void OsgWidget::initializeGL() -{ - _passiveWin->init(); - _timer = new QTimer(this); - connect(_timer, SIGNAL(timeout()), this, SLOT(updateGL())); - _timer->start(2000); -} - -void OsgWidget::resizeGL(int w, int h) -{ - _passiveWin->resize(w,h); -} - -void OsgWidget::paintGL() -{ - _mgr->redraw(); -} \ No newline at end of file diff --git a/OpenSG/OsgWidget.h b/OpenSG/OsgWidget.h deleted file mode 100644 index 0eccd072b2a6bfd3d446b3d0ac16730c30032ac8..0000000000000000000000000000000000000000 --- a/OpenSG/OsgWidget.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * \file OsgWidget.h - * 24/08/2010 LB Initial implementation - */ - -#ifndef OSGWIDGET_H -#define OSGWIDGET_H - -#include <QGLWidget> -#include <QTimer> - -#include <OpenSG/OSGConfig.h> -#include <OpenSG/OSGPassiveWindow.h> -#include <OpenSG/OSGSimpleSceneManager.h> - -class OsgWidget : public QGLWidget -{ - Q_OBJECT - -public: - OsgWidget(QWidget *parent=0, const QGLWidget *shareWidget=0, Qt::WindowFlags f=0); - OsgWidget(QGLContext *context, QWidget *parent=0, const QGLWidget *shareWidget=0, Qt::WindowFlags f=0); - OsgWidget(const QGLFormat &format, QWidget *parent=0, const QGLWidget *shareWidget=0, Qt::WindowFlags f=0); - virtual ~OsgWidget(); - - inline OSG::SimpleSceneManager* sceneManager(); - inline OSG::PassiveWindowRefPtr window(); - -protected: - void initializeGL(); - void resizeGL(int w, int h); - void paintGL(); - -private: - QTimer *_timer; - OSG::PassiveWindowRefPtr _passiveWin; - OSG::SimpleSceneManager* _mgr; -}; - -inline OSG::SimpleSceneManager* OsgWidget::sceneManager(){ - return _mgr; -} - -inline OSG::PassiveWindowRefPtr OsgWidget::window(){ - return _passiveWin; -} - -#endif // OSGWIDGET_H diff --git a/OpenSG/vtkOsgActor.cpp b/OpenSG/vtkOsgActor.cpp deleted file mode 100644 index a6740368311e147ac5589662f325d058b6c81ca0..0000000000000000000000000000000000000000 --- a/OpenSG/vtkOsgActor.cpp +++ /dev/null @@ -1,901 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////////////// -// By Bjoern Zehner 2006/2010 // -// UFZ-Helmholtz Center for Environmental Research Leipzig // -// Permoser Str. 15, D-04318 Leizig, Germany // -///////////////////////////////////////////////////////////////////////////////////////// -// Class for translating VTK Objects into OpenSG representations, derives from vtkActor// -// See Project/file VtkOsgActorTestXXX for an example for the use // - - -#include "vtkOsgActor.h" - -#include "vtkMapper.h" -#include "vtkDataSet.h" -#include "vtkDataSetMapper.h" - - - -vtkOsgActor::vtkOsgActor(void) : vtkOpenGLActor(), - m_pvtkNormals(NULL), - m_pvtkTexCoords(NULL), - m_pvtkColors(NULL), - m_pvtkTexture(NULL), - m_bTextureHasChanged(false), - m_iColorType(NOT_GIVEN), - m_iNormalType(NOT_GIVEN), - m_bVerbose(false), - m_iNumPoints(0), - m_iNumNormals(0), - m_iNumColors(0), - m_iNumGLPoints(0), - m_iNumGLLineStrips(0), - m_iNumGLPolygons(0), - m_iNumGLTriStrips(0), - m_iNumGLPrimitives(0), - m_posgRoot(NullFC), - m_posgTransform(NullFC), - m_posgGeomNode(NullFC), - m_posgGeometry(NullFC), - m_posgMaterial(NullFC), - m_posgMaterialChunk(NullFC), - m_posgTextureChunk(NullFC), - m_posgPolygonChunk(NullFC), - m_posgImage(NullFC), - m_posgTypes(NullFC), - m_posgLengths(NullFC), - m_posgIndices(NullFC), - m_posgPoints(NullFC), - m_posgColors(NullFC), - m_posgNormals(NullFC), - m_posgTexCoords(NullFC) -{ - TransformPtr tptr; - m_posgRoot = makeCoredNode<osg::Transform>(&tptr); - m_posgTransform = tptr; -} - -vtkOsgActor::~vtkOsgActor(void) -{ - m_posgRoot = NullFC; - - //Open SG Objects are deleted via the reference counting scheme - ClearOsg(); -} - -void vtkOsgActor::InitOpenSG(){ - m_posgGeomNode = Node::create(); - m_posgGeometry = Geometry::create(); - m_posgMaterial = ChunkMaterial::create(); - m_posgMaterialChunk = MaterialChunk::create(); - m_posgTextureChunk = TextureChunk::create(); - m_posgPolygonChunk = PolygonChunk::create(); - m_posgImage = Image::create(); - beginEditCP(m_posgRoot);{ - m_posgRoot->addChild(m_posgGeomNode); - };endEditCP(m_posgRoot); - beginEditCP(m_posgGeomNode);{ - m_posgGeomNode->setCore(m_posgGeometry); - };endEditCP(m_posgGeomNode); - m_posgTypes = GeoPTypesUI8::create(); - m_posgLengths = GeoPLengthsUI32::create(); - m_posgIndices = GeoIndicesUI32::create(); - m_posgPoints = GeoPositions3f::create(); - m_posgColors = GeoColors3f::create(); - m_posgNormals = GeoNormals3f::create(); - m_posgTexCoords = GeoTexCoords2d::create(); -} - -vtkOsgActor *vtkOsgActor::New(){ - // First try to create the object from the vtkGraphicsFactory - vtkObject* ret = vtkObjectFactory::CreateInstance("vtkOsgActor"); - - if (ret) { - return static_cast<vtkOsgActor*>(ret); - } - return new vtkOsgActor; -} - -void vtkOsgActor::PrintSelf(ostream& os, vtkIndent indent){ - vtkOpenGLActor::PrintSelf(os, indent); - - // beside this nothing is done so far ... -} - -void vtkOsgActor::Render(vtkRenderer *ren, vtkMapper *mapper){ - vtkOpenGLActor::Render(ren, mapper); -} - -void vtkOsgActor::UpdateOsg(){ - if (m_posgGeomNode == NullFC) InitOpenSG(); - if (m_bTextureHasChanged) CreateTexture(); - - this->GetMapper()->Update(); - - LookForNormals(); - LookForColors(); - LookForTexCoords(); - LookForArraySizes(); - CreateTexture(); - - double scaling[3]; - //double translation[3]; - //double rotation[3]; - - //this->GetPosition(translation); - this->GetScale(scaling); - - if (m_bVerbose){ - std::cout << "set scaling: " << scaling[0] << " " << scaling[1] << " " << scaling[2] << std::endl; - } - - osg::Matrix m; - m.setIdentity(); - m.setScale(scaling[0], scaling[1], scaling[2]); - beginEditCP(m_posgTransform);{ - m_posgTransform->setMatrix(m); - };endEditCP(m_posgTransform); - - NodePtr newNodePtr = this->GetNodePtr(); - - if (m_iNormalType == NOT_GIVEN){ - GeometryPtr newGeometryPtr = GeometryPtr::dcast(newNodePtr->getCore()); - if ((newGeometryPtr != NullFC) && (m_iColorType == PER_VERTEX)){ - std::cout << "WARNING: Normals are missing in the vtk layer, calculating normals per vertex!" << std::endl; - calcVertexNormals(newGeometryPtr); - } else if ((newGeometryPtr != NullFC) && (m_iColorType == PER_CELL)){ - std::cout << "WARNING: Normals are missing in the vtk layer, calculating normals per face!" << std::endl; - calcFaceNormals(newGeometryPtr); - } else if (newGeometryPtr != NullFC){ - std::cout << "WARNING: Normals are missing in the vtk layer, calculating normals per vertex!" << std::endl; - calcVertexNormals(newGeometryPtr); - } - } - - beginEditCP(m_posgRoot);{ - m_posgRoot->addChild(newNodePtr); - };endEditCP(m_posgRoot); -} - -void vtkOsgActor::ClearOsg(){ - //This also decrements the reference count, possibly deleting the objects - m_posgGeomNode = NullFC; - m_posgGeometry = NullFC; - m_posgMaterial = NullFC; - m_posgMaterialChunk = NullFC; - m_posgTextureChunk = NullFC; - m_posgPolygonChunk = NullFC; - m_posgImage = NullFC; - m_posgTypes = NullFC; - m_posgLengths = NullFC; - m_posgIndices = NullFC; - m_posgPoints = NullFC; - m_posgColors = NullFC; - m_posgNormals = NullFC; - m_posgTexCoords = NullFC; - m_bTextureHasChanged = true; -} - -void vtkOsgActor::SetVerbose(bool value){ - m_bVerbose = value; -} - -void vtkOsgActor::SetTexture(vtkTexture *vtkTex){ - m_pvtkTexture = vtkTex; - m_bTextureHasChanged = true; - vtkOpenGLActor::SetTexture(vtkTex); -} - -NodePtr vtkOsgActor::GetOsgRoot(){ - return m_posgRoot; -} - -void vtkOsgActor::LookForNormals(){ - vtkPolyData *pPolyData = NULL; - if (dynamic_cast<vtkPolyDataMapper*>(this->GetMapper())){ - pPolyData = (vtkPolyData*) this->GetMapper()->GetInput(); - if (m_bVerbose){ - std::cerr << "Using vtkPolyDataMapper directly" << std::endl; - } - } else if (dynamic_cast<vtkDataSetMapper*>(this->GetMapper())){ - vtkDataSetMapper *dataSetMapper = (vtkDataSetMapper*) this->GetMapper(); - pPolyData = (vtkPolyData*) dataSetMapper->GetPolyDataMapper()->GetInput(); - if (m_bVerbose){ - std::cerr << "Using vtkPolyDataMapper via the vtkDataSetMapper" << std::endl; - } - } - - m_iNormalType = NOT_GIVEN; - if (pPolyData == NULL) return; - - if (this->GetProperty()->GetInterpolation() == VTK_FLAT){ - m_pvtkNormals = pPolyData->GetCellData()->GetNormals(); - if (m_pvtkNormals != NULL) m_iNormalType = PER_CELL; - }else{ - m_pvtkNormals = pPolyData->GetPointData()->GetNormals(); - if (m_pvtkNormals != NULL) m_iNormalType = PER_VERTEX; - } - if (m_bVerbose){ - if (m_iNormalType != NOT_GIVEN){ - std::cerr << " number of normals: " << m_pvtkNormals->GetNumberOfTuples() << std::endl; - std::cerr << " normals are given: "; - std::cerr << ((m_iNormalType == PER_VERTEX) ? "per vertex" : "per cell") << std::endl; - }else{ - std::cerr << " no normals are given" << std::endl; - } - } -} - -void vtkOsgActor::LookForColors(){ - vtkPolyData *pPolyData = NULL; - vtkPolyDataMapper *pPolyDataMapper = NULL; - if (dynamic_cast<vtkPolyDataMapper*>(this->GetMapper())){ - pPolyDataMapper = (vtkPolyDataMapper*) this->GetMapper(); - pPolyData = (vtkPolyData*) pPolyDataMapper->GetInput(); - if (m_bVerbose){ - std::cerr << "Using vtkPolyDataMapper directly" << std::endl; - } - } else if (dynamic_cast<vtkDataSetMapper*>(this->GetMapper())){ - vtkDataSetMapper *dataSetMapper = (vtkDataSetMapper*) this->GetMapper(); - pPolyDataMapper = dataSetMapper->GetPolyDataMapper(); - pPolyData = (vtkPolyData*) pPolyDataMapper->GetInput(); - if (m_bVerbose){ - std::cerr << "Using vtkPolyDataMapper via the vtkDataSetMapper" << std::endl; - } - } - m_iColorType = NOT_GIVEN; - if (pPolyData == NULL) return; - if (pPolyDataMapper == NULL) return; - - //m_pvtkColors = pPolyDataMapper->MapScalars(1.0); - //if (pPolyDataMapper->GetScalarVisibility() && (m_pvtkColors != NULL)){ - if (pPolyDataMapper->GetScalarVisibility()){ - int iScalarMode = pPolyDataMapper->GetScalarMode(); - m_pvtkColors = pPolyDataMapper->MapScalars(1.0); - if (m_pvtkColors == NULL){ - m_iColorType = NOT_GIVEN; - } else if (iScalarMode == VTK_SCALAR_MODE_USE_CELL_DATA){ - m_iColorType = PER_CELL; - } else if (iScalarMode == VTK_SCALAR_MODE_USE_POINT_DATA){ - m_iColorType = PER_VERTEX; - } else if (iScalarMode == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA){ - std::cerr << "WARNING: Can not process colours with scalar mode using cell field data!" << std::endl; - m_iColorType = NOT_GIVEN; - } else if (iScalarMode == VTK_SCALAR_MODE_USE_POINT_FIELD_DATA){ - std::cerr << "WARNING: Can not process colours with scalar mode using point field data!" << std::endl; - m_iColorType = NOT_GIVEN; - } else if (iScalarMode == VTK_SCALAR_MODE_DEFAULT){ - //Bummer, we do not know what it is. may be we can make a guess - int numColors = m_pvtkColors->GetNumberOfTuples(); - vtkPoints *points = pPolyData->GetPoints(); - int numPoints = points->GetNumberOfPoints(); - int numCells = pPolyData->GetVerts()->GetNumberOfCells(); - numCells += pPolyData->GetLines()->GetNumberOfCells(); - numCells += pPolyData->GetPolys()->GetNumberOfCells(); - numCells += pPolyData->GetStrips()->GetNumberOfCells(); - if (numColors == 0){ - m_iColorType = NOT_GIVEN; - } else if (numColors == numPoints){ - m_iColorType = PER_VERTEX; - } else if (numColors == numCells){ - m_iColorType = PER_CELL; - } else { - m_iColorType = NOT_GIVEN; - } - } - } - if (m_bVerbose){ - if (m_iColorType != NOT_GIVEN){ - std::cerr << " number of colors: " << m_pvtkColors->GetNumberOfTuples() << std::endl; - std::cerr << " colors are given: "; - std::cerr << ((m_iColorType == PER_VERTEX) ? "per vertex" : "per cell") << std::endl; - }else{ - std::cerr << " no colors are given" << std::endl; - } - } -} - -void vtkOsgActor::LookForTexCoords(){ - vtkPolyData *pPolyData = NULL; - if (dynamic_cast<vtkPolyDataMapper*>(this->GetMapper())){ - pPolyData = (vtkPolyData*) this->GetMapper()->GetInput(); - if (m_bVerbose){ - std::cerr << "Using vtkPolyDataMapper directly" << std::endl; - } - } else if (dynamic_cast<vtkDataSetMapper*>(this->GetMapper())){ - vtkDataSetMapper *dataSetMapper = (vtkDataSetMapper*) this->GetMapper(); - pPolyData = (vtkPolyData*) dataSetMapper->GetPolyDataMapper()->GetInput(); - if (m_bVerbose){ - std::cerr << "Using vtkPolyDataMapper via the vtkDataSetMapper" << std::endl; - } - } - if (pPolyData == NULL) return; - - vtkPointData *pointData = pPolyData->GetPointData(); - if (pointData == NULL) return; - m_pvtkTexCoords = pointData->GetTCoords(); - if (m_bVerbose){ - if (m_pvtkTexCoords != NULL){ - std::cerr << " found tex-coords: " << m_pvtkTexCoords->GetNumberOfTuples() << std::endl; - } else { - std::cerr << " no tex-coords where given" << std::endl; - } - } -} - -void vtkOsgActor::LookForArraySizes(){ - vtkPolyData *pPolyData = NULL; - if (dynamic_cast<vtkPolyDataMapper*>(this->GetMapper())){ - pPolyData = (vtkPolyData*) this->GetMapper()->GetInput(); - if (m_bVerbose){ - std::cerr << "Using vtkPolyDataMapper directly" << std::endl; - } - } else if (dynamic_cast<vtkDataSetMapper*>(this->GetMapper())){ - vtkDataSetMapper *dataSetMapper = (vtkDataSetMapper*) this->GetMapper(); - pPolyData = (vtkPolyData*) dataSetMapper->GetPolyDataMapper()->GetInput(); - if (m_bVerbose){ - std::cerr << "Using vtkPolyDataMapper via the vtkDataSetMapper" << std::endl; - } - } - if (pPolyData == NULL) return; - - m_iNumPoints = pPolyData->GetNumberOfPoints(); - m_iNumGLPoints = pPolyData->GetVerts()->GetNumberOfCells(); - m_iNumGLLineStrips = pPolyData->GetLines()->GetNumberOfCells(); - m_iNumGLPolygons = pPolyData->GetPolys()->GetNumberOfCells(); - m_iNumGLTriStrips = pPolyData->GetStrips()->GetNumberOfCells(); - m_iNumGLPrimitives = m_iNumGLPoints + m_iNumGLLineStrips + m_iNumGLPolygons + m_iNumGLTriStrips; - - - if (m_bVerbose){ - std::cerr << " number of vertices: " << m_iNumPoints << std::endl; - std::cerr << " number of GL_POINTS: " << m_iNumGLPoints << std::endl; - std::cerr << " number of GL_LINE_STRIPS: " << m_iNumGLLineStrips << std::endl; - std::cerr << " number of GL_POLYGON's: " << m_iNumGLPolygons << std::endl; - std::cerr << " number of GL_TRIANGLE_STRIPS: " << m_iNumGLTriStrips << std::endl; - std::cerr << " number of primitives: " << m_iNumGLPrimitives << std::endl; - } -} - -void vtkOsgActor::CreateTexture(){ - if (m_bVerbose){ - std::cerr << "Calling CreateTexture()" << std::endl; - } - if (! m_bTextureHasChanged){ - if (m_bVerbose){ - std::cerr << " ... nothing to do" << std::endl; - std::cerr << " End CreateTexture()" << std::endl; - } - //can we check if the actual image has been updated, even if the texture is the same? - return; - } else if (m_pvtkTexture == NULL){ - if (m_bVerbose){ - std::cerr << " ... texture is (still ?) NULL" << std::endl; - std::cerr << " EndCreateTexture()" << std::endl; - } - //the texture has changed but it is NULL now. We should remove the texture from the material - return; - } - m_bTextureHasChanged = false; - - vtkImageData *imgData = m_pvtkTexture->GetInput(); - int iImgDims[3]; - imgData->GetDimensions(iImgDims); - - vtkPointData *imgPointData = imgData->GetPointData(); - vtkCellData *imgCellData = imgData->GetCellData(); - - vtkDataArray *data = NULL; - - if (imgPointData != NULL){ - if (NULL != imgPointData->GetScalars()){ - data = imgPointData->GetScalars(); - if (m_bVerbose) std::cout << " found texture data in point data" << std::endl; - } - } - - if (imgCellData != NULL){ - if (NULL != imgCellData->GetScalars()){ - data = imgCellData->GetScalars(); - if (m_bVerbose) std::cout << " found texture data in cell data" << std::endl; - } - } - - if (data == NULL){ - std::cerr << " could not load texture data" << std::endl; - return; - } - - int iImgComps = data->GetNumberOfComponents(); - int iImgPixels = data->GetNumberOfTuples(); - if (iImgPixels != (iImgDims[0] * iImgDims[1] * iImgDims[2])){ - std::cout << "Number of pixels in data array seems to be wrong!" << std::endl; - return; - } - - UInt8 *newImageData = new UInt8[iImgDims[0] * iImgDims[1] * iImgDims[2] * iImgComps]; - vtkUnsignedCharArray *oldImageUChar = NULL; - oldImageUChar = dynamic_cast<vtkUnsignedCharArray*>(data); - int ucharCounter = 0; - if (oldImageUChar != NULL){ - for (int i=0; i<iImgPixels; i++){ - unsigned char pixel[4]; - oldImageUChar->GetTupleValue(i, pixel); - for (int j=0; j<iImgComps; j++){ - newImageData[ucharCounter + j] = pixel[j]; - } - ucharCounter += iImgComps; - } - } else { - std::cout << "Pixel data come in unsupported vtk type" << std::endl; - } - - beginEditCP(m_posgImage);{ - m_posgImage->setWidth(iImgDims[0]); - m_posgImage->setHeight(iImgDims[1]); - m_posgImage->setDepth(iImgDims[2]); - m_posgImage->setDataType(Image::OSG_UINT8_IMAGEDATA); - if (iImgComps == 1){ - m_posgImage->setPixelFormat(Image::OSG_L_PF); - } else if (iImgComps == 3){ - m_posgImage->setPixelFormat(Image::OSG_RGB_PF); - } else if (iImgComps == 4){ - m_posgImage->setPixelFormat(Image::OSG_RGBA_PF); - } else { - std::cout << "Unsupported image type!" << std::endl; - delete [] newImageData; - return; - } - m_posgImage->setData(newImageData); - };endEditCP(m_posgImage); - - beginEditCP(m_posgTextureChunk);{ - m_posgTextureChunk->setImage(m_posgImage.get()); - };endEditCP(m_posgTextureChunk); - - if (m_bVerbose){ - std::cerr << " Loading image with " << iImgDims[0] << " x " << iImgDims[1] << " x " << iImgDims[2] << "pixels." << std::endl; - std::cerr << " components: " << iImgComps << std::endl; - std::cerr << " End CreateTexture()" << std::endl; - } -} - -ChunkMaterialPtr vtkOsgActor::CreateMaterial(){ - if (m_bVerbose){ - std::cerr << "Start CreateMaterial()" << std::endl; - } - vtkProperty *prop = this->GetProperty(); - double *diffuseColor = prop->GetDiffuseColor(); - double *ambientColor = prop->GetAmbientColor(); - double *specularColor = prop->GetSpecularColor(); - double specularPower = prop->GetSpecularPower(); - - double diffuse = prop->GetDiffuse(); - double ambient = prop->GetAmbient(); - double specular = prop->GetSpecular(); - - //float opacity = prop->GetOpacity(); - int representation = prop->GetRepresentation(); - - if (m_bVerbose){ - std::cerr << " Colors:" << std::endl; - std::cerr << " diffuse " << diffuse << " * " << diffuseColor[0] << " " << diffuseColor[1] << " " << diffuseColor[2] << std::endl; - std::cerr << " ambient " << ambient << " * " << ambientColor[0] << " " << ambientColor[1] << " " << ambientColor[2] << std::endl; - std::cerr << " specular " << specular << " * " << specularColor[0] << " " << specularColor[1] << " " << specularColor[2] << std::endl; - } - - beginEditCP(m_posgPolygonChunk);{ - if (representation == VTK_SURFACE){ - m_posgPolygonChunk->setFrontMode(GL_FILL); - m_posgPolygonChunk->setBackMode(GL_FILL); - }else if (representation == VTK_WIREFRAME){ - m_posgPolygonChunk->setFrontMode(GL_LINE); - m_posgPolygonChunk->setBackMode(GL_LINE); - }else{ - m_posgPolygonChunk->setFrontMode(GL_POINT); - m_posgPolygonChunk->setBackMode(GL_POINT); - } - };endEditCP(m_posgPolygonChunk); - - beginEditCP(m_posgMaterialChunk);{ - m_posgMaterialChunk->setDiffuse(Color4f(diffuseColor[0]*diffuse, diffuseColor[1]*diffuse, diffuseColor[2]*diffuse, 1.0)); - m_posgMaterialChunk->setSpecular(Color4f(specularColor[0]*specular, specularColor[1]*specular, specularColor[2]*specular, 1.0)); - m_posgMaterialChunk->setAmbient(Color4f(ambientColor[0]*ambient, ambientColor[1]*ambient, ambientColor[2]*ambient, 1.0)); - m_posgMaterialChunk->setShininess(specularPower); - m_posgMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE); - //m_posgMaterialChunk->setTransparency(1.0f - opacity); // 1-opacity ? - };endEditCP(m_posgMaterialChunk); - - beginEditCP(m_posgMaterial);{ - m_posgMaterial->addChunk(m_posgMaterialChunk); - m_posgMaterial->addChunk(TwoSidedLightingChunk::create()); - m_posgMaterial->addChunk(m_posgPolygonChunk); - - if (m_pvtkTexCoords != NULL){ - if (m_bVerbose){ - std::cerr << " Add TextureChunk" << std::endl; - } - m_posgMaterial->addChunk(m_posgTextureChunk); - } else { - if (m_bVerbose){ - std::cerr << " Not adding TextureChunk" << std::endl; - } - } - }endEditCP(m_posgMaterial); - return m_posgMaterial; - if (m_bVerbose){ - std::cerr << " End CreateMaterial()" << std::endl; - } -} - -NodePtr vtkOsgActor::ProcessGeometryNormalsAndColorsPerVertex(){ - if (m_bVerbose){ - std::cerr << "Start ProcessGeometryNormalsAndColorsPerVertex()" << std::endl; - } - - beginEditCP(m_posgTypes);{ - m_posgTypes->clear(); - };endEditCP(m_posgTypes); - - beginEditCP(m_posgLengths);{ - m_posgLengths->clear(); - };endEditCP(m_posgLengths); - - beginEditCP(m_posgIndices);{ - m_posgIndices->clear(); - };endEditCP(m_posgIndices); - - beginEditCP(m_posgPoints);{ - m_posgPoints->clear(); - };endEditCP(m_posgPoints); - - beginEditCP(m_posgColors);{ - m_posgColors->clear(); - };endEditCP(m_posgColors); - - beginEditCP(m_posgNormals);{ - m_posgNormals->clear(); - };endEditCP(m_posgNormals); - - beginEditCP(m_posgTexCoords);{ - m_posgTexCoords->clear(); - };endEditCP(m_posgTexCoords); - - int iNumPoints = 0; - int iNumNormals = 0; - int iNumColors = 0; - int i; - - vtkPolyData *pPolyData = NULL; - if (dynamic_cast<vtkPolyDataMapper*>(this->GetMapper())){ - pPolyData = (vtkPolyData*) this->GetMapper()->GetInput(); - if (m_bVerbose){ - std::cerr << " Using vtkPolyDataMapper directly" << std::endl; - } - } else if (dynamic_cast<vtkDataSetMapper*>(this->GetMapper())){ - vtkDataSetMapper *dataSetMapper = (vtkDataSetMapper*) this->GetMapper(); - pPolyData = (vtkPolyData*) dataSetMapper->GetPolyDataMapper()->GetInput(); - if (m_bVerbose){ - std::cerr << " Using vtkPolyDataMapper via the vtkDataSetMapper" << std::endl; - } - } - if (pPolyData == NULL) return NullFC; - - //getting the vertices: - beginEditCP(m_posgPoints);{ - iNumPoints = pPolyData->GetNumberOfPoints(); - for (i=0; i<iNumPoints; i++){ - double *aVertex = pPolyData->GetPoint(i); - m_posgPoints->addValue(Vec3f(aVertex[0], aVertex[1], aVertex[2])); - } - }endEditCP(m_posgPoints); - - //possibly getting the normals - if (m_iNormalType == PER_VERTEX){ - iNumNormals = m_pvtkNormals->GetNumberOfTuples(); - beginEditCP(m_posgNormals);{ - double *aNormal; - for (i=0; i<iNumNormals; i++){ - aNormal = m_pvtkNormals->GetTuple(i); - m_posgNormals->addValue(Vec3f(aNormal[0], aNormal[1], aNormal[2])); - } - }endEditCP(m_posgNormals); - if (iNumNormals != iNumPoints){ - std::cerr << "WARNING: CVtkActorToOpenSG::ProcessGeometryNormalsAndColorsPerVertex() number of normals" << std::endl; - std::cerr << "should equal the number of vertices (points)!" << std::endl << std::endl; - } - } - - //possibly getting the colors - if (m_iColorType == PER_VERTEX){ - iNumColors = m_pvtkColors->GetNumberOfTuples(); - beginEditCP(m_posgColors);{ - unsigned char aColor[4]; - for (i=0; i<iNumColors; i++){ - m_pvtkColors->GetTupleValue(i, aColor); - float r = ((float) aColor[0]) / 255.0f; - float g = ((float) aColor[1]) / 255.0f; - float b = ((float) aColor[2]) / 255.0f; - m_posgColors->addValue(Color3f(r, g, b)); - } - }endEditCP(m_posgColors); - if (iNumColors != iNumPoints){ - std::cerr << "WARNING: CVtkActorToOpenSG::ProcessGeometryNormalsAndColorsPerVertex() number of colors" << std::endl; - std::cerr << "should equal the number of vertices (points)!" << std::endl << std::endl; - } - } - - //possibly getting the texture coordinates. These are alwary per vertex - if (m_pvtkTexCoords != NULL){ - int numTuples = m_pvtkTexCoords->GetNumberOfTuples(); - for (i=0; i<numTuples; i++){ - double texCoords[3]; - m_pvtkTexCoords->GetTuple(i, texCoords); - m_posgTexCoords->addValue(Vec2f(texCoords[0], texCoords[1])); - } - } - - //getting the cells - beginEditCP(m_posgTypes); - beginEditCP(m_posgLengths); - beginEditCP(m_posgIndices);{ - vtkCellArray *pCells; - vtkIdType npts, *pts; - int prim; - - prim = 0; - pCells = pPolyData->GetVerts(); - if (pCells->GetNumberOfCells() > 0){ - for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++){ - m_posgLengths->addValue(npts); - m_posgTypes->addValue(GL_POINTS); - for (i=0; i<npts; i++){ - m_posgIndices->addValue(pts[i]); - } - } - } - - prim = 0; - pCells = pPolyData->GetLines(); - if (pCells->GetNumberOfCells() > 0){ - for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++){ - m_posgLengths->addValue(npts); - m_posgTypes->addValue(GL_LINE_STRIP); - for (i=0; i<npts; i++){ - m_posgIndices->addValue(pts[i]); - } - } - } - - prim = 0; - pCells = pPolyData->GetPolys(); - if (pCells->GetNumberOfCells() > 0){ - for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++){ - m_posgLengths->addValue(npts); - m_posgTypes->addValue(GL_POLYGON); - for (i=0; i<npts; i++){ - m_posgIndices->addValue(pts[i]); - } - } - } - - prim = 0; - pCells = pPolyData->GetStrips(); - if (pCells->GetNumberOfCells() > 0){ - for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++){ - m_posgLengths->addValue(npts); - m_posgTypes->addValue(GL_TRIANGLE_STRIP); - for (i=0; i<npts; i++){ - m_posgIndices->addValue(pts[i]); - } - } - } - }endEditCP(m_posgIndices); - endEditCP(m_posgLengths); - endEditCP(m_posgTypes); - - ChunkMaterialPtr material = CreateMaterial(); - beginEditCP(m_posgGeometry);{ - m_posgGeometry->setPositions(m_posgPoints); - m_posgGeometry->setTypes(m_posgTypes); - m_posgGeometry->setLengths(m_posgLengths); - m_posgGeometry->setIndices(m_posgIndices); - m_posgGeometry->setMaterial(material); - - if (m_iNormalType == PER_VERTEX) m_posgGeometry->setNormals(m_posgNormals); - if (m_iColorType == PER_VERTEX) m_posgGeometry->setColors(m_posgColors); - if (m_posgTexCoords->getSize() > 0) m_posgGeometry->setTexCoords(m_posgTexCoords); - };endEditCP(m_posgGeometry); - if (m_bVerbose){ - std::cerr << " Start ProcessGeometryNormalsAndColorsPerVertex()" << std::endl; - } - return m_posgGeomNode; -} - -NodePtr vtkOsgActor::ProcessGeometryNonIndexedCopyAttributes(int gl_primitive_type){ - if (m_bVerbose){ - std::cout << "Start ProcessGeometryNonIndexedCopyAttributes(int gl_primitive_type)" << std::endl; - } - - beginEditCP(m_posgTypes);{ - m_posgTypes->clear(); - };endEditCP(m_posgTypes); - - beginEditCP(m_posgLengths);{ - m_posgLengths->clear(); - };endEditCP(m_posgLengths); - - beginEditCP(m_posgIndices);{ - m_posgIndices->clear(); - };endEditCP(m_posgIndices); - - beginEditCP(m_posgPoints);{ - m_posgPoints->clear(); - };endEditCP(m_posgPoints); - - beginEditCP(m_posgColors);{ - m_posgColors->clear(); - };endEditCP(m_posgColors); - - beginEditCP(m_posgNormals);{ - m_posgNormals->clear(); - };endEditCP(m_posgNormals); - - beginEditCP(m_posgTexCoords);{ - m_posgTexCoords->clear(); - };endEditCP(m_posgTexCoords); - - vtkPolyData *pPolyData = NULL; - if (dynamic_cast<vtkPolyDataMapper*>(this->GetMapper())){ - pPolyData = (vtkPolyData*) this->GetMapper()->GetInput(); - if (m_bVerbose){ - std::cerr << " Using vtkPolyDataMapper directly" << std::endl; - } - } else if (dynamic_cast<vtkDataSetMapper*>(this->GetMapper())){ - vtkDataSetMapper *dataSetMapper = (vtkDataSetMapper*) this->GetMapper(); - pPolyData = (vtkPolyData*) dataSetMapper->GetPolyDataMapper()->GetInput(); - if (m_bVerbose){ - std::cerr << " Using vtkPolyDataMapper via the vtkDataSetMapper" << std::endl; - } - } - if (pPolyData == NULL) return NullFC; - - vtkCellArray *pCells; - if (gl_primitive_type == GL_POINTS){ - pCells = pPolyData->GetVerts(); - } else if (gl_primitive_type == GL_LINE_STRIP){ - pCells = pPolyData->GetLines(); - } else if (gl_primitive_type == GL_POLYGON){ - pCells = pPolyData->GetPolys(); - } else if (gl_primitive_type == GL_TRIANGLE_STRIP){ - pCells = pPolyData->GetStrips(); - } else { - std::cerr << "CVtkActorToOpenSG::ProcessGeometryNonIndexedCopyAttributes(int gl_primitive_type)" << std::endl; - std::cerr << " was called with non implemented gl_primitive_type!" << std::endl; - return NullFC; - } - - beginEditCP(m_posgTypes); - beginEditCP(m_posgLengths); - beginEditCP(m_posgPoints); - beginEditCP(m_posgColors); - beginEditCP(m_posgNormals);{ - int prim = 0; - if (pCells->GetNumberOfCells() > 0){ - vtkIdType npts, *pts; - for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++){ - m_posgLengths->addValue(npts); - m_posgTypes->addValue(GL_POLYGON); - for (int i=0; i<npts; i++){ - double *aVertex; - double *aNormal; - unsigned char aColor[4]; - - aVertex = pPolyData->GetPoint(pts[i]); - m_posgPoints->addValue(Vec3f(aVertex[0], aVertex[1], aVertex[2])); - - if (m_iNormalType == PER_VERTEX){ - aNormal = m_pvtkNormals->GetTuple(pts[i]); - m_posgNormals->addValue(Vec3f(aNormal[0], aNormal[1], aNormal[2])); - } else if (m_iNormalType == PER_CELL){ - aNormal = m_pvtkNormals->GetTuple(prim); - m_posgNormals->addValue(Vec3f(aNormal[0], aNormal[1], aNormal[2])); - } - - if (m_iColorType == PER_VERTEX){ - m_pvtkColors->GetTupleValue(pts[i], aColor); - float r = ((float) aColor[0]) / 255.0f; - float g = ((float) aColor[1]) / 255.0f; - float b = ((float) aColor[2]) / 255.0f; - m_posgColors->addValue(Color3f(r, g, b)); - } else if (m_iColorType == PER_CELL){ - m_pvtkColors->GetTupleValue(prim, aColor); - float r = ((float) aColor[0]) / 255.0f; - float g = ((float) aColor[1]) / 255.0f; - float b = ((float) aColor[2]) / 255.0f; - m_posgColors->addValue(Color3f(r, g, b)); - } - } - } - } - };endEditCP(m_posgTypes); - endEditCP(m_posgLengths); - endEditCP(m_posgPoints); - endEditCP(m_posgColors); - endEditCP(m_posgNormals); - - //possibly getting the texture coordinates. These are always per vertex - vtkPoints *points = pPolyData->GetPoints(); - if ((m_pvtkTexCoords != NULL) && (points != NULL)){ - int numPoints = points->GetNumberOfPoints(); - int numTexCoords = m_pvtkTexCoords->GetNumberOfTuples(); - if (numPoints == numTexCoords){ - beginEditCP(m_posgTexCoords);{ - int numTuples = m_pvtkTexCoords->GetNumberOfTuples(); - for (int i=0; i<numTuples; i++){ - double texCoords[3]; - m_pvtkTexCoords->GetTuple(i, texCoords); - m_posgTexCoords->addValue(Vec2f(texCoords[0], texCoords[1])); - } - };endEditCP(m_posgTexCoords); - } - } - - ChunkMaterialPtr material = CreateMaterial(); - //GeometryPtr geo = Geometry::create(); - beginEditCP(m_posgGeometry);{ - m_posgGeometry->setPositions(m_posgPoints); - m_posgGeometry->setTypes(m_posgTypes); - m_posgGeometry->setLengths(m_posgLengths); - m_posgGeometry->setMaterial(material); - - if (m_iNormalType != NOT_GIVEN) m_posgGeometry->setNormals(m_posgNormals); - if (m_iColorType != NOT_GIVEN) m_posgGeometry->setColors(m_posgColors); - if (m_posgTexCoords->getSize() > 0) m_posgGeometry->setTexCoords(m_posgTexCoords); - //geo->setMaterial(getDefaultMaterial()); - }endEditCP(m_posgGeometry); - - if (m_bVerbose){ - std::cout << " End ProcessGeometryNonIndexedCopyAttributes(int gl_primitive_type)" << std::endl; - } - return m_posgGeomNode; -} - -NodePtr vtkOsgActor::GetNodePtr(){ - if (m_bVerbose){ - std::cerr << "Calling GetNodePtr()" << std::endl; - } - - this->GetMapper()->Update(); - - //Rendering with OpenSG simple indexed geometry - if (((m_iNormalType == PER_VERTEX) || (m_iNormalType == NOT_GIVEN)) && - ((m_iColorType == PER_VERTEX) || (m_iColorType == NOT_GIVEN))){ - return this->ProcessGeometryNormalsAndColorsPerVertex(); - }else{ - //Rendering with OpenSG non indexed geometry by copying a lot of attribute data - if (m_iNumGLPolygons > 0){ - if (m_iNumGLPolygons != m_iNumGLPrimitives){ - std::cerr << "WARNING: vtkActor contains different kind of primitives" << std::endl; - } - return this->ProcessGeometryNonIndexedCopyAttributes(GL_POLYGON); - } else if (m_iNumGLLineStrips > 0){ - if (m_iNumGLLineStrips != m_iNumGLPrimitives){ - std::cerr << "WARNING: vtkActor contains different kind of primitives" << std::endl; - } - return this->ProcessGeometryNonIndexedCopyAttributes(GL_LINE_STRIP); - } else if (m_iNumGLTriStrips > 0){ - if (m_iNumGLTriStrips != m_iNumGLPrimitives){ - std::cerr << "WARNING: vtkActor contains different kind of primitives" << std::endl; - } - return this->ProcessGeometryNonIndexedCopyAttributes(GL_TRIANGLE_STRIP); - } else if (m_iNumGLPoints > 0){ - if (m_iNumGLPoints != m_iNumGLPrimitives){ - std::cerr << "WARNING: vtkActor contains different kind of primitives" << std::endl; - } - return this->ProcessGeometryNonIndexedCopyAttributes(GL_POINTS); - } else { - return NullFC; - } - } - return NullFC; -} diff --git a/OpenSG/vtkOsgActor.h b/OpenSG/vtkOsgActor.h deleted file mode 100644 index a1a27f7df8e93ad15d6599a54d716c1d81ced0a6..0000000000000000000000000000000000000000 --- a/OpenSG/vtkOsgActor.h +++ /dev/null @@ -1,127 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////////////// -// By Bjoern Zehner 2006/2010 // -// UFZ-Helmholtz Center for Environmental Research Leipzig // -// Permoser Str. 15, D-04318 Leizig, Germany // -///////////////////////////////////////////////////////////////////////////////////////// -// Class for translating VTK Objects into OpenSG representations, derives from vtkActor// -// See Project/file VtkOsgActorTestXXX for an example for the use // - -#pragma once -#include "vtkOpenGLActor.h" - -#include "vtkObjectFactory.h" -#include "vtkTimeStamp.h" - -#include <vtkActor.h> -#include <vtkPolyDataMapper.h> -#include <vtkMapper.h> -#include <vtkPolyData.h> -#include <vtkDataSet.h> -#include <vtkPointData.h> -#include <vtkProperty.h> -#include <vtkCellData.h> -#include <vtkCellArray.h> -#include <vtkTexture.h> -#include <vtkImageData.h> - -#include <OpenSG/OSGRefPtr.h> -#include <OpenSG/OSGNode.h> -#include <OpenSG/OSGTransform.h> -#include <OpenSG/OSGMatrix.h> -#include <OpenSG/OSGSimpleGeometry.h> -#include <OpenSG/OSGSimpleMaterial.h> -#include <OpenSG/OSGChunkMaterial.h> -#include <OpenSG/OSGMaterialChunk.h> -#include <OpenSG/OSGTextureChunk.h> -#include <OpenSG/OSGGeoFunctions.h> -#include <OpenSG/OSGGroup.h> -#include <OpenSG/OSGTwoSidedLightingChunk.h> -#include <OpenSG/OSGPolygonChunk.h> -#include <OpenSG/OSGGeoFunctions.h> -#include <OpenSG/OSGTransform.h> -#include <OpenSG/OSGImage.h> - -OSG_USING_NAMESPACE - -class vtkOsgActor : public vtkOpenGLActor -{ -protected: - vtkOsgActor(void); - virtual ~vtkOsgActor(void); - void InitOpenSG(void); - -public: //VTK related - vtkTypeMacro(vtkOsgActor,vtkOpenGLActor); - static vtkOsgActor* New(); - void PrintSelf(ostream& os, vtkIndent indent); - void Render(vtkRenderer *ren, vtkMapper *mapper); - -public: //The added value - OpenSG related stuff - void UpdateOsg(); - void ClearOsg(); - void SetVerbose(bool value); - void SetTexture(vtkTexture *vtkTex); - NodePtr GetOsgRoot(); - -private: - vtkDataArray *m_pvtkNormals; - vtkDataArray *m_pvtkTexCoords; - vtkUnsignedCharArray *m_pvtkColors; - vtkTexture *m_pvtkTexture; - bool m_bTextureHasChanged; - - enum {NOT_GIVEN, PER_VERTEX, PER_CELL}; - int m_iColorType; - int m_iNormalType; - bool m_bVerbose; - - int m_iNumPoints; - int m_iNumNormals; - int m_iNumColors; - int m_iNumGLPoints; - int m_iNumGLLineStrips; - int m_iNumGLPolygons; - int m_iNumGLTriStrips; - int m_iNumGLPrimitives; - - //For the translation to OpenSG - RefPtr<NodePtr> m_posgRoot; - RefPtr<TransformPtr> m_posgTransform; - RefPtr<NodePtr> m_posgGeomNode; - RefPtr<GeometryPtr> m_posgGeometry; - RefPtr<ChunkMaterialPtr> m_posgMaterial; - RefPtr<MaterialChunkPtr> m_posgMaterialChunk; - RefPtr<TextureChunkPtr> m_posgTextureChunk; - RefPtr<PolygonChunkPtr> m_posgPolygonChunk; - RefPtr<ImagePtr> m_posgImage; - - RefPtr<GeoPTypesPtr> m_posgTypes; - RefPtr<GeoPLengthsPtr> m_posgLengths; - RefPtr<GeoIndicesUI32Ptr> m_posgIndices; - RefPtr<GeoPositions3fPtr> m_posgPoints; - RefPtr<GeoColors3fPtr> m_posgColors; - RefPtr<GeoNormals3fPtr> m_posgNormals; - RefPtr<GeoTexCoords2dPtr> m_posgTexCoords; - -private: - vtkOsgActor(const vtkOsgActor&); // Not implemented. - void operator=(const vtkActor&); // Not implemented. - -private: - //for the translation to OpenSG - void LookForNormals(); - void LookForColors(); - void LookForTexCoords(); - void LookForArraySizes(); - - void CreateTexture(); - ChunkMaterialPtr CreateMaterial(); - - //Can use OpenSG simple indexed geometry - NodePtr ProcessGeometryNormalsAndColorsPerVertex(); - - //Can't use indexing and so requires a lot of storage space - NodePtr ProcessGeometryNonIndexedCopyAttributes(int gl_primitive_type); - - NodePtr GetNodePtr(); -}; diff --git a/OpenSG/vtkOsgConverter.cpp b/OpenSG/vtkOsgConverter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f1ecf9867178018ca9162cb0ae12af52f75e4510 --- /dev/null +++ b/OpenSG/vtkOsgConverter.cpp @@ -0,0 +1,859 @@ +/** + * \file vtkOsgConverter.cpp + * 27/07/2011 LB Initial implementation + * + * Implementation of vtkOsgConverter class + */ + +// ** INCLUDES ** +#include "vtkOsgConverter.h" + +#include <vtkActor.h> +#include <vtkTexture.h> +#include <vtkDataArray.h> +#include <vtkUnsignedCharArray.h> +#include <vtkPolyData.h> +#include <vtkPolyDataMapper.h> +#include <vtkProperty.h> +#include <vtkPointData.h> +#include <vtkCellData.h> +#include <vtkCellArray.h> +#include <vtkImageData.h> +#include <vtkMapper.h> +#include <vtkDataSet.h> +#include <vtkDataSetMapper.h> +#include <vtkSmartPointer.h> +#include <vtkCompositeDataGeometryFilter.h> +#include <vtkGeometryFilter.h> + +#include <OpenSG/OSGPolygonChunk.h> +#include <OpenSG/OSGPointChunk.h> +#include <OpenSG/OSGLineChunk.h> +#include <OpenSG/OSGMatrix.h> +#include <OpenSG/OSGSimpleGeometry.h> +#include <OpenSG/OSGMaterialChunk.h> +#include <OpenSG/OSGGeoFunctions.h> +#include <OpenSG/OSGGroup.h> +#include <OpenSG/OSGTwoSidedLightingChunk.h> +#include <OpenSG/OSGImage.h> + +OSG_USING_NAMESPACE + +vtkOsgConverter::vtkOsgConverter(vtkActor* actor) : + _actor(actor), + _verbose(false), + _osgRoot(NullFC), + _osgTransform(NullFC) +{ + TransformPtr tptr; + _osgRoot = makeCoredNode<osg::Transform>(&tptr); + _osgTransform = tptr; + _mapper = _actor->GetMapper(); +} + +vtkOsgConverter::~vtkOsgConverter(void) +{ + _osgRoot = NullFC; +} + +bool vtkOsgConverter::WriteAnActor() +{ + + + // see if the actor has a mapper. it could be an assembly + if (_actor->GetMapper() == NULL) + return false; + // dont export when not visible + if (_actor->GetVisibility() == 0) + return false; + + vtkDataObject* inputDO = _actor->GetMapper()->GetInputDataObject(0, 0); + if (inputDO == NULL) + return false; + + // Get PolyData. Convert if necessary becasue we only want polydata + vtkSmartPointer<vtkPolyData> pd; + if(inputDO->IsA("vtkCompositeDataSet")) + { + vtkCompositeDataGeometryFilter* gf = vtkCompositeDataGeometryFilter::New(); + gf->SetInput(inputDO); + gf->Update(); + pd = gf->GetOutput(); + gf->Delete(); + } + else if(inputDO->GetDataObjectType() != VTK_POLY_DATA) + { + vtkGeometryFilter *gf = vtkGeometryFilter::New(); + gf->SetInput(inputDO); + gf->Update(); + pd = gf->GetOutput(); + gf->Delete(); + } + else + pd = static_cast<vtkPolyData *>(inputDO); + + // Copy mapper to a new one + vtkPolyDataMapper* pm = vtkPolyDataMapper::New(); + pm->SetInput(pd); + pm->SetScalarRange(_actor->GetMapper()->GetScalarRange()); + pm->SetScalarVisibility(_actor->GetMapper()->GetScalarVisibility()); + pm->SetLookupTable(_actor->GetMapper()->GetLookupTable()); + pm->SetScalarMode(_actor->GetMapper()->GetScalarMode()); + + if(pm->GetScalarMode() == VTK_SCALAR_MODE_USE_POINT_FIELD_DATA || + pm->GetScalarMode() == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA ) + { + if(_actor->GetMapper()->GetArrayAccessMode() == VTK_GET_ARRAY_BY_ID ) + pm->ColorByArrayComponent(_actor->GetMapper()->GetArrayId(), + _actor->GetMapper()->GetArrayComponent()); + else + pm->ColorByArrayComponent(_actor->GetMapper()->GetArrayName(), + _actor->GetMapper()->GetArrayComponent()); + } + + _mapper = pm; + // vtkPoints* points = pd->GetPoints(); + vtkPointData* pntData = pd->GetPointData(); + bool hasTexCoords = false; + vtkUnsignedCharArray* vtkColors = pm->MapScalars(1.0); + + // ARRAY SIZES + vtkIdType m_iNumPoints = pd->GetNumberOfPoints(); + if (m_iNumPoints == 0) + return false; + vtkIdType m_iNumGLPoints = pd->GetVerts()->GetNumberOfCells(); + vtkIdType m_iNumGLLineStrips = pd->GetLines()->GetNumberOfCells(); + vtkIdType m_iNumGLPolygons = pd->GetPolys()->GetNumberOfCells(); + vtkIdType m_iNumGLTriStrips = pd->GetStrips()->GetNumberOfCells(); + vtkIdType m_iNumGLPrimitives = m_iNumGLPoints + m_iNumGLLineStrips + m_iNumGLPolygons + m_iNumGLTriStrips; + bool lit = !(m_iNumGLPolygons == 0 && m_iNumGLTriStrips == 0); + + if (_verbose) + { + std::cout << "Array sizes:" << std::endl; + std::cout << " number of vertices: " << m_iNumPoints << std::endl; + std::cout << " number of GL_POINTS: " << m_iNumGLPoints << std::endl; + std::cout << " number of GL_LINE_STRIPS: " << m_iNumGLLineStrips << std::endl; + std::cout << " number of GL_POLYGON's: " << m_iNumGLPolygons << std::endl; + std::cout << " number of GL_TRIANGLE_STRIPS: " << m_iNumGLTriStrips << std::endl; + std::cout << " number of primitives: " << m_iNumGLPrimitives << std::endl; + } + + _mapper->Update(); + + // NORMALS + vtkDataArray *vtkNormals = NULL; + int m_iNormalType = NOT_GIVEN; + if (_actor->GetProperty()->GetInterpolation() == VTK_FLAT) + { + vtkNormals = pd->GetCellData()->GetNormals(); + if (vtkNormals != NULL) m_iNormalType = PER_CELL; + } + else + { + vtkNormals = pntData->GetNormals(); + if (vtkNormals != NULL) m_iNormalType = PER_VERTEX; + } + if (_verbose) + { + std::cout << "Normals:" << std::endl; + if (m_iNormalType != NOT_GIVEN) + { + std::cout << " number of normals: " << vtkNormals->GetNumberOfTuples() << std::endl; + std::cout << " normals are given: "; + std::cout << ((m_iNormalType == PER_VERTEX) ? "per vertex" : "per cell") << std::endl; + } + else + std::cout << " no normals are given" << std::endl; + } + + // COLORS + int m_iColorType = NOT_GIVEN; + if(pm->GetScalarVisibility()) + { + int iScalarMode = pm->GetScalarMode(); + if(vtkColors == NULL) + { + m_iColorType = NOT_GIVEN; + std::cout << "WARNING: MapScalars(1.0) did not return array!" << std::endl; + } + else if(iScalarMode == VTK_SCALAR_MODE_USE_CELL_DATA) + m_iColorType = PER_CELL; + else if(iScalarMode == VTK_SCALAR_MODE_USE_POINT_DATA) + m_iColorType = PER_VERTEX; + else if(iScalarMode == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA) + { + std::cout << "WARNING TO BE REMOVED: Can not process colours with scalar mode using cell field data!" << std::endl; + m_iColorType = PER_CELL; + } + else if(iScalarMode == VTK_SCALAR_MODE_USE_POINT_FIELD_DATA) + { + std::cout << "WARNING TO BE REMOVED: Can not process colours with scalar mode using point field data!" << std::endl; + m_iColorType = PER_VERTEX; + } + else if(iScalarMode == VTK_SCALAR_MODE_DEFAULT) + { + //Bummer, we do not know what it is. may be we can make a guess + int numColors = vtkColors->GetNumberOfTuples(); + if (numColors == 0) + { + m_iColorType = NOT_GIVEN; + std::cout << "WARNING: No colors found!" << std::endl; + } + else if (numColors == m_iNumPoints) + m_iColorType = PER_VERTEX; + else if (numColors == m_iNumGLPrimitives) + m_iColorType = PER_CELL; + else + { + m_iColorType = NOT_GIVEN; + std::cout << "WARNING: Number of colors do not match number of points / cells!" << std::endl; + } + } + } + if (_verbose) + { + std::cout << "Colors:" << std::endl; + if (m_iColorType != NOT_GIVEN){ + std::cout << " number of colors: " << vtkColors->GetNumberOfTuples() << std::endl; + std::cout << " colors are given: " << ((m_iColorType == PER_VERTEX) ? "per vertex" : "per cell") << std::endl; + }else{ + std::cout << " no colors are given" << std::endl; + } + } + + // TEXCOORDS + vtkDataArray* vtkTexCoords = pntData->GetTCoords(); + if (_verbose) + { + std::cout << "Tex-coords:" << std::endl; + if (vtkTexCoords) + { + std::cout << " Number of tex-coords: " << vtkTexCoords->GetNumberOfTuples() << std::endl; + hasTexCoords = true; + } + else + std::cout << " No tex-coords where given" << std::endl; + } + + // TRANSFORMATION + double scaling[3]; + double translation[3]; + // double rotation[3]; + + _actor->GetPosition(translation); + _actor->GetScale(scaling); + //_actor->GetRotation(rotation[0], rotation[1], rotation[2]); + + if (_verbose) + std::cout << "set scaling: " << scaling[0] << " " << scaling[1] << " " << scaling[2] << std::endl; + + osg::Matrix m; + m.setIdentity(); + m.setTranslate(translation[0], translation[1], translation[2]); + m.setScale(scaling[0], scaling[1], scaling[2]); + // TODO QUATERNION m.setRotate(rotation[0], rotation[1], rotation[2]) + beginEditCP(_osgTransform); + _osgTransform->setMatrix(m); + endEditCP(_osgTransform); + + _mapper->Update(); + + // Get the converted OpenSG node + NodePtr osgGeomNode = Node::create(); + GeometryPtr osgGeometry = Geometry::create(); + beginEditCP(osgGeomNode); + osgGeomNode->setCore(osgGeometry); + endEditCP(osgGeomNode); + + bool osgConversionSuccess = false; + + GeoPTypesPtr osgTypes = GeoPTypesUI8::create(); + GeoPLengthsPtr osgLengths = GeoPLengthsUI32::create(); + GeoIndicesUI32Ptr osgIndices = GeoIndicesUI32::create(); + GeoPositions3fPtr osgPoints = GeoPositions3f::create(); + GeoNormals3fPtr osgNormals = GeoNormals3f::create(); + GeoColors3fPtr osgColors = GeoColors3f::create(); + GeoTexCoords2dPtr osgTexCoords = GeoTexCoords2d::create(); + + //Rendering with OpenSG simple indexed geometry + if (((m_iNormalType == PER_VERTEX) || (m_iNormalType == NOT_GIVEN)) && + ((m_iColorType == PER_VERTEX) || (m_iColorType == NOT_GIVEN))) + { + if (_verbose) + std::cout << "Start ProcessGeometryNormalsAndColorsPerVertex()" << std::endl; + + //getting the vertices: + beginEditCP(osgPoints);{ + for (int i=0; i<m_iNumPoints; i++) + { + double *aVertex = pd->GetPoint(i); + osgPoints->addValue(Vec3f(aVertex[0], aVertex[1], aVertex[2])); + } + }endEditCP(osgPoints); + + //possibly getting the normals + if (m_iNormalType == PER_VERTEX) + { + vtkIdType iNumNormals = vtkNormals->GetNumberOfTuples(); + beginEditCP(osgNormals);{ + double *aNormal; + for (int i=0; i<iNumNormals; i++) + { + aNormal = vtkNormals->GetTuple(i); + osgNormals->addValue(Vec3f(aNormal[0], aNormal[1], aNormal[2])); + } + }endEditCP(osgNormals); + if (iNumNormals != m_iNumPoints) + { + std::cout << "WARNING: CVtkActorToOpenSG::ProcessGeometryNormalsAndColorsPerVertex() number of normals" << std::endl; + std::cout << "should equal the number of vertices (points)!" << std::endl << std::endl; + } + } + + //possibly getting the colors + if (m_iColorType == PER_VERTEX) + { + vtkIdType iNumColors = vtkColors->GetNumberOfTuples(); + beginEditCP(osgColors);{ + unsigned char aColor[4]; + for (int i=0; i<iNumColors; i++) + { + vtkColors->GetTupleValue(i, aColor); + float r = ((float) aColor[0]) / 255.0f; + float g = ((float) aColor[1]) / 255.0f; + float b = ((float) aColor[2]) / 255.0f; + osgColors->addValue(Color3f(r, g, b)); + } + }endEditCP(osgColors); + if (iNumColors != m_iNumPoints) + { + std::cout << "WARNING: CVtkActorToOpenSG::ProcessGeometryNormalsAndColorsPerVertex() number of colors" << std::endl; + std::cout << "should equal the number of vertices (points)!" << std::endl << std::endl; + } + } + + //possibly getting the texture coordinates. These are alwary per vertex + if (vtkTexCoords != NULL) + { + int numTuples = vtkTexCoords->GetNumberOfTuples(); + for (int i=0; i<numTuples; i++) + { + double texCoords[3]; + vtkTexCoords->GetTuple(i, texCoords); + osgTexCoords->addValue(Vec2f(texCoords[0], texCoords[1])); + } + } + + //getting the cells + beginEditCP(osgTypes); + beginEditCP(osgLengths); + beginEditCP(osgIndices);{ + vtkCellArray *pCells; + vtkIdType npts, *pts; + int prim; + + prim = 0; + pCells = pd->GetVerts(); + if (pCells->GetNumberOfCells() > 0) + { + for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++) + { + osgLengths->addValue(npts); + osgTypes->addValue(GL_POINTS); + for (int i=0; i<npts; i++) + osgIndices->addValue(pts[i]); + } + } + + prim = 0; + pCells = pd->GetLines(); + if (pCells->GetNumberOfCells() > 0) + { + for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++) + { + osgLengths->addValue(npts); + osgTypes->addValue(GL_LINE_STRIP); + for (int i=0; i<npts; i++) + osgIndices->addValue(pts[i]); + } + } + + prim = 0; + pCells = pd->GetPolys(); + if (pCells->GetNumberOfCells() > 0) + { + for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++) + { + osgLengths->addValue(npts); + osgTypes->addValue(GL_POLYGON); + for (int i=0; i<npts; i++) + osgIndices->addValue(pts[i]); + } + } + + prim = 0; + pCells = pd->GetStrips(); + if (pCells->GetNumberOfCells() > 0) + { + for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++) + { + osgLengths->addValue(npts); + osgTypes->addValue(GL_TRIANGLE_STRIP); + for (int i=0; i<npts; i++) + osgIndices->addValue(pts[i]); + } + } + }endEditCP(osgIndices); + endEditCP(osgLengths); + endEditCP(osgTypes); + + ChunkMaterialPtr material = CreateMaterial(lit, hasTexCoords); + beginEditCP(osgGeometry);{ + osgGeometry->setPositions(osgPoints); + osgGeometry->setTypes(osgTypes); + osgGeometry->setLengths(osgLengths); + osgGeometry->setIndices(osgIndices); + osgGeometry->setMaterial(material); + + if (m_iNormalType == PER_VERTEX) osgGeometry->setNormals(osgNormals); + if (m_iColorType == PER_VERTEX) osgGeometry->setColors(osgColors); + if (osgTexCoords->getSize() > 0) osgGeometry->setTexCoords(osgTexCoords); + };endEditCP(osgGeometry); + + osgConversionSuccess = true; + + if (_verbose) + std::cout << " End ProcessGeometryNormalsAndColorsPerVertex()" << std::endl; + } + else + { + //Rendering with OpenSG non indexed geometry by copying a lot of attribute data + if (_verbose) + std::cout << "Start ProcessGeometryNonIndexedCopyAttributes(int gl_primitive_type)" << std::endl; + int gl_primitive_type = -1; + if(m_iNumGLPolygons > 0) + { + if(m_iNumGLPolygons != m_iNumGLPrimitives) + std::cout << "WARNING: vtkActor contains different kind of primitives" << std::endl; + gl_primitive_type = GL_POLYGON; + //osgConversionSuccess = this->ProcessGeometryNonIndexedCopyAttributes(GL_POLYGON, pd, osgGeometry); + } + else if(m_iNumGLLineStrips > 0) + { + if (m_iNumGLLineStrips != m_iNumGLPrimitives) + std::cout << "WARNING: vtkActor contains different kind of primitives" << std::endl; + gl_primitive_type = GL_LINE_STRIP; + //osgConversionSuccess = this->ProcessGeometryNonIndexedCopyAttributes(GL_LINE_STRIP, pd osgGeometry); + } + else if(m_iNumGLTriStrips > 0) + { + if (m_iNumGLTriStrips != m_iNumGLPrimitives) + std::cout << "WARNING: vtkActor contains different kind of primitives" << std::endl; + gl_primitive_type = GL_TRIANGLE_STRIP; + //osgConversionSuccess = this->ProcessGeometryNonIndexedCopyAttributes(GL_TRIANGLE_STRIP, pd osgGeometry); + } + else if (m_iNumGLPoints > 0) + { + if (m_iNumGLPoints != m_iNumGLPrimitives) + std::cout << "WARNING: vtkActor contains different kind of primitives" << std::endl; + gl_primitive_type = GL_POINTS; + //osgConversionSuccess = this->ProcessGeometryNonIndexedCopyAttributes(GL_POINTS, pd osgGeometry); + } + if(gl_primitive_type != -1) + { + vtkCellArray *pCells; + if (gl_primitive_type == GL_POINTS) + pCells = pd->GetVerts(); + else if (gl_primitive_type == GL_LINE_STRIP) + pCells = pd->GetLines(); + else if (gl_primitive_type == GL_POLYGON) + pCells = pd->GetPolys(); + else if (gl_primitive_type == GL_TRIANGLE_STRIP) + pCells = pd->GetStrips(); + else + { + std::cout << "CVtkActorToOpenSG::ProcessGeometryNonIndexedCopyAttributes(int gl_primitive_type)" << std::endl; + std::cout << " was called with non implemented gl_primitive_type!" << std::endl; + } + + beginEditCP(osgTypes); + beginEditCP(osgLengths); + beginEditCP(osgPoints); + beginEditCP(osgColors); + beginEditCP(osgNormals);{ + int prim = 0; + if (pCells->GetNumberOfCells() > 0) + { + vtkIdType npts, *pts; + for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++) + { + osgLengths->addValue(npts); + osgTypes->addValue(GL_POLYGON); + for (int i=0; i<npts; i++) + { + double *aVertex; + double *aNormal; + unsigned char aColor[4]; + + aVertex = pd->GetPoint(pts[i]); + osgPoints->addValue(Vec3f(aVertex[0], aVertex[1], aVertex[2])); + + if (m_iNormalType == PER_VERTEX) + { + aNormal = vtkNormals->GetTuple(pts[i]); + osgNormals->addValue(Vec3f(aNormal[0], aNormal[1], aNormal[2])); + } + else if (m_iNormalType == PER_CELL) + { + aNormal = vtkNormals->GetTuple(prim); + osgNormals->addValue(Vec3f(aNormal[0], aNormal[1], aNormal[2])); + } + + if (m_iColorType == PER_VERTEX) + { + vtkColors->GetTupleValue(pts[i], aColor); + float r = ((float) aColor[0]) / 255.0f; + float g = ((float) aColor[1]) / 255.0f; + float b = ((float) aColor[2]) / 255.0f; + osgColors->addValue(Color3f(r, g, b)); + } + else if (m_iColorType == PER_CELL) + { + vtkColors->GetTupleValue(prim, aColor); + float r = ((float) aColor[0]) / 255.0f; + float g = ((float) aColor[1]) / 255.0f; + float b = ((float) aColor[2]) / 255.0f; + osgColors->addValue(Color3f(r, g, b)); + } + } + } + } + };endEditCP(osgTypes); + endEditCP(osgLengths); + endEditCP(osgPoints); + endEditCP(osgColors); + endEditCP(osgNormals); + + //possibly getting the texture coordinates. These are always per vertex + vtkPoints *points = pd->GetPoints(); + if ((vtkTexCoords != NULL) && (points != NULL)) + { + int numPoints = points->GetNumberOfPoints(); + int numTexCoords = vtkTexCoords->GetNumberOfTuples(); + if (numPoints == numTexCoords){ + beginEditCP(osgTexCoords);{ + int numTuples = vtkTexCoords->GetNumberOfTuples(); + for (int i=0; i<numTuples; i++) + { + double texCoords[3]; + vtkTexCoords->GetTuple(i, texCoords); + osgTexCoords->addValue(Vec2f(texCoords[0], texCoords[1])); + } + };endEditCP(osgTexCoords); + } + } + + ChunkMaterialPtr material = CreateMaterial(lit, hasTexCoords); + //GeometryPtr geo = Geometry::create(); + beginEditCP(osgGeometry);{ + osgGeometry->setPositions(osgPoints); + osgGeometry->setTypes(osgTypes); + osgGeometry->setLengths(osgLengths); + osgGeometry->setMaterial(material); + + if (m_iNormalType != NOT_GIVEN) osgGeometry->setNormals(osgNormals); + if (m_iColorType != NOT_GIVEN) osgGeometry->setColors(osgColors); + if (osgTexCoords->getSize() > 0) osgGeometry->setTexCoords(osgTexCoords); + //geo->setMaterial(getDefaultMaterial()); + }endEditCP(osgGeometry); + + osgConversionSuccess = true; + } + if (_verbose) + std::cout << " End ProcessGeometryNonIndexedCopyAttributes(int gl_primitive_type)" << std::endl; + } + + if(!osgConversionSuccess) + { + std::cout << "OpenSG converter was not able to convert this actor." << std::endl; + return false; + } + + if(m_iNormalType == NOT_GIVEN) + { + //GeometryPtr newGeometryPtr = GeometryPtr::dcast(newNodePtr->getCore()); + if((osgGeometry != NullFC) && (m_iColorType == PER_VERTEX)) + { + std::cout << "WARNING: Normals are missing in the vtk layer, calculating normals per vertex!" << std::endl; + calcVertexNormals(osgGeometry); + } + else if ((osgGeometry != NullFC) && (m_iColorType == PER_CELL)) + { + std::cout << "WARNING: Normals are missing in the vtk layer, calculating normals per face!" << std::endl; + calcFaceNormals(osgGeometry); + } + else if (osgGeometry != NullFC) + { + std::cout << "WARNING: Normals are missing in the vtk layer, calculating normals per vertex!" << std::endl; + calcVertexNormals(osgGeometry); + } + } + + std::cout << "Conversion finished." << std::endl; + + // Add node to root + beginEditCP(_osgRoot); + _osgRoot->addChild(osgGeomNode); + endEditCP(_osgRoot); + + return true; +} + +void vtkOsgConverter::SetVerbose(bool value) +{ + _verbose = value; +} + +NodePtr vtkOsgConverter::GetOsgNode() +{ + return _osgRoot; +} + +TextureChunkPtr vtkOsgConverter::CreateTexture(vtkTexture* vtkTexture) +{ + if(_verbose) + std::cout << "Calling CreateTexture()" << std::endl; + + // if(! m_bTextureHasChanged) + // { + // if (_verbose) + // { + // std::cout << " ... nothing to do" << std::endl; + // std::cout << " End CreateTexture()" << std::endl; + // } + // //can we check if the actual image has been updated, even if the texture is the same? + // return; + // } + // else if(m_pvtkTexture == NULL) + // { + // if (_verbose) + // { + // std::cout << " ... texture is (still ?) NULL" << std::endl; + // std::cout << " EndCreateTexture()" << std::endl; + // } + // //the texture has changed but it is NULL now. We should remove the texture from the material + // return; + // } + // m_bTextureHasChanged = false; + + vtkImageData *imgData = vtkTexture->GetInput(); + int iImgDims[3]; + imgData->GetDimensions(iImgDims); + + vtkPointData *imgPointData = imgData->GetPointData(); + vtkCellData *imgCellData = imgData->GetCellData(); + + vtkDataArray *data = NULL; + + if (imgPointData != NULL) + { + if (NULL != imgPointData->GetScalars()) + { + data = imgPointData->GetScalars(); + if (_verbose) std::cout << " found texture data in point data" << std::endl; + } + } + + if (imgCellData != NULL) + { + if (NULL != imgCellData->GetScalars()) + { + data = imgCellData->GetScalars(); + if (_verbose) std::cout << " found texture data in cell data" << std::endl; + } + } + + if (data == NULL) + { + std::cout << " could not load texture data" << std::endl; + return NullFC; + } + + int iImgComps = data->GetNumberOfComponents(); + int iImgPixels = data->GetNumberOfTuples(); + if (iImgPixels != (iImgDims[0] * iImgDims[1] * iImgDims[2])) + { + std::cout << "Number of pixels in data array seems to be wrong!" << std::endl; + return NullFC; + } + + UInt8 *newImageData = new UInt8[iImgDims[0] * iImgDims[1] * iImgDims[2] * iImgComps]; + vtkUnsignedCharArray *oldImageUChar = NULL; + oldImageUChar = dynamic_cast<vtkUnsignedCharArray*>(data); + int ucharCounter = 0; + if (oldImageUChar != NULL) + { + for (int i=0; i<iImgPixels; i++) + { + unsigned char pixel[4]; + oldImageUChar->GetTupleValue(i, pixel); + for (int j=0; j<iImgComps; j++) + newImageData[ucharCounter + j] = pixel[j]; + ucharCounter += iImgComps; + } + } + else + std::cout << "Pixel data come in unsupported vtk type" << std::endl; + + ImagePtr osgImage = Image::create(); + beginEditCP(osgImage);{ + osgImage->setWidth(iImgDims[0]); + osgImage->setHeight(iImgDims[1]); + osgImage->setDepth(iImgDims[2]); + osgImage->setDataType(Image::OSG_UINT8_IMAGEDATA); + if (iImgComps == 1) + osgImage->setPixelFormat(Image::OSG_L_PF); + else if (iImgComps == 3) + osgImage->setPixelFormat(Image::OSG_RGB_PF); + else if (iImgComps == 4) + osgImage->setPixelFormat(Image::OSG_RGBA_PF); + else + { + std::cout << "Unsupported image type!" << std::endl; + delete [] newImageData; + return NullFC; + } + osgImage->setData(newImageData); + };endEditCP(osgImage); + + TextureChunkPtr osgTextureChunk = TextureChunk::create(); + beginEditCP(osgTextureChunk);{ + osgTextureChunk->setImage(osgImage); + };endEditCP(osgTextureChunk); + + if (_verbose) + { + std::cout << " Loading image with " << iImgDims[0] << " x " << iImgDims[1] << " x " << iImgDims[2] << "pixels." << std::endl; + std::cout << " components: " << iImgComps << std::endl; + std::cout << "End CreateTexture()" << std::endl; + } + + return osgTextureChunk; +} + +ChunkMaterialPtr vtkOsgConverter::CreateMaterial(bool lit, bool hasTexCoords) +{ + if (_verbose) + std::cout << "Start CreateMaterial()" << std::endl; + + vtkProperty *prop = _actor->GetProperty(); + double *diffuseColor = prop->GetDiffuseColor(); + double *ambientColor = prop->GetAmbientColor(); + double *specularColor = prop->GetSpecularColor(); + double specularPower = prop->GetSpecularPower(); + + double diffuse = prop->GetDiffuse(); + double ambient = prop->GetAmbient(); + double specular = prop->GetSpecular(); + double opacity = prop->GetOpacity(); + + float pointSize = prop->GetPointSize(); + float lineWidth = prop->GetLineWidth(); + // int lineStipplePattern = prop->GetLineStipplePattern(); + + int representation = prop->GetRepresentation(); + + if (_verbose) + { + std::cout << " Colors:" << std::endl; + std::cout << " diffuse " << diffuse << " * " << diffuseColor[0] << " " << diffuseColor[1] << " " << diffuseColor[2] << std::endl; + std::cout << " ambient " << ambient << " * " << ambientColor[0] << " " << ambientColor[1] << " " << ambientColor[2] << std::endl; + std::cout << " specular " << specular << " * " << specularColor[0] << " " << specularColor[1] << " " << specularColor[2] << std::endl; + } + + + PolygonChunkPtr polygonChunk = PolygonChunk::create(); + beginEditCP(polygonChunk);{ + if (representation == VTK_SURFACE) + { + polygonChunk->setFrontMode(GL_FILL); + polygonChunk->setBackMode(GL_FILL); + } + else if (representation == VTK_WIREFRAME) + { + polygonChunk->setFrontMode(GL_LINE); + polygonChunk->setBackMode(GL_LINE); + } + else + { + polygonChunk->setFrontMode(GL_POINT); + polygonChunk->setBackMode(GL_POINT); + } + };endEditCP(polygonChunk); + + MaterialChunkPtr osgMaterialChunk = MaterialChunk::create(); + beginEditCP(osgMaterialChunk);{ + osgMaterialChunk->setDiffuse(Color4f(diffuseColor[0]*diffuse, diffuseColor[1]*diffuse, diffuseColor[2]*diffuse, opacity)); + osgMaterialChunk->setSpecular(Color4f(specularColor[0]*specular, specularColor[1]*specular, specularColor[2]*specular, 1.0)); + osgMaterialChunk->setAmbient(Color4f(ambientColor[0]*ambient, ambientColor[1]*ambient, ambientColor[2]*ambient, opacity)); + osgMaterialChunk->setShininess(specularPower); + + //if(opacity < 1.0) + //{ + // osgMaterialChunk->setColorMaterial(GL_AMBIENT); // HACK: Opacity does not work with GL_AMBIENT_AND_DIFFUSE + //osgMaterialChunk->setTransparency(1.0f - opacity); + //} + //else + osgMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE); + + // On objects consisting only of points or lines, dont lit + if(!lit) + osgMaterialChunk->setLit(false); + + };endEditCP(osgMaterialChunk); + + ChunkMaterialPtr osgChunkMaterial = ChunkMaterial::create(); + beginEditCP(osgChunkMaterial);{ + osgChunkMaterial->addChunk(osgMaterialChunk); + osgChunkMaterial->addChunk(TwoSidedLightingChunk::create()); + osgChunkMaterial->addChunk(polygonChunk); + + if(pointSize > 1.0f) + { + PointChunkPtr pointChunk = PointChunk::create(); + pointChunk->setSize(pointSize); + osgChunkMaterial->addChunk(pointChunk); + } + + if(lineWidth > 1.0f) + { + LineChunkPtr lineChunk = LineChunk::create(); + lineChunk->setWidth(lineWidth); + osgChunkMaterial->addChunk(lineChunk); + } + + // TEXTURE + if (hasTexCoords) + { + vtkTexture* vtkTexture = _actor->GetTexture(); + if (vtkTexture) + { + TextureChunkPtr osgTextureChunk = NullFC; + osgTextureChunk = CreateTexture(vtkTexture); + + if(osgTextureChunk != NullFC) + { + if (_verbose) + std::cout << " Add TextureChunk" << std::endl; + osgChunkMaterial->addChunk(osgTextureChunk); + } + } + } + }endEditCP(osgChunkMaterial); + + if (_verbose) + std::cout << " End CreateMaterial()" << std::endl; + + return osgChunkMaterial; +} diff --git a/OpenSG/vtkOsgConverter.h b/OpenSG/vtkOsgConverter.h new file mode 100644 index 0000000000000000000000000000000000000000..81b0ccdd227e4c7f915b116a08cc19c90d0cd1b4 --- /dev/null +++ b/OpenSG/vtkOsgConverter.h @@ -0,0 +1,60 @@ +/** + * \file vtkOsgConverter.h + * 27/07/2011 LB Initial implementation + * Derived from class vtkOsgActor from Bjoern Zehner + */ + +#ifndef VTKOSGCONVERTER_H +#define VTKOSGCONVERTER_H + +#include <OpenSG/OSGRefPtr.h> +#include <OpenSG/OSGNode.h> +#include <OpenSG/OSGTransform.h> +#include <OpenSG/OSGTextureChunk.h> +#include <OpenSG/OSGChunkMaterial.h> + +class vtkActor; +class vtkMapper; +class vtkTexture; + +/// @brief Converts a vtkActor to an OpenSG-Node. +/// Example usage: +/// +/// @code +/// vtkOsgConverter* osgConverter = new vtkOsgConverter(aVtkActor); +/// if(osgConverter->WriteAnActor()) +/// { +/// beginEditCP(rootNode); +/// rootNode->addChild(osgConverter->GetOsgNode()); +/// endEditCP(rootNode); +/// } +/// @endcode +class vtkOsgConverter +{ +public: + vtkOsgConverter(vtkActor* actor); + virtual ~vtkOsgConverter(); + + bool WriteAnActor(); + void SetVerbose(bool value); + OSG::NodePtr GetOsgNode(); + +protected: + +private: + vtkActor* _actor; + vtkMapper* _mapper; + + enum {NOT_GIVEN, PER_VERTEX, PER_CELL}; + bool _verbose; + + + //For the translation to OpenSG + OSG::RefPtr<OSG::NodePtr> _osgRoot; + OSG::RefPtr<OSG::TransformPtr> _osgTransform; + + OSG::TextureChunkPtr CreateTexture(vtkTexture* vtkTexture); + OSG::ChunkMaterialPtr CreateMaterial(bool lit, bool hasTexCoords); +}; + +#endif // VTKOSGCONVERTER_H \ No newline at end of file diff --git a/VtkVis/CMakeLists.txt b/VtkVis/CMakeLists.txt index 6f3cb44896467cda1be22c3cab3823dbf9e2764d..31a585ba9cbd96865a9f00958b2c84abbee38e4d 100644 --- a/VtkVis/CMakeLists.txt +++ b/VtkVis/CMakeLists.txt @@ -35,9 +35,11 @@ SET( SOURCES VtkTextureOnSurfaceFilter.cpp VtkTrackedCamera.cpp VtkVisHelper.cpp + VtkVisImageItem.cpp VtkVisPipeline.cpp VtkVisPipelineItem.cpp VtkVisPipelineView.cpp + VtkVisPointSetItem.cpp VtkVisTabWidget.cpp ) @@ -53,7 +55,6 @@ SET( MOC_HEADERS VtkAlgorithmPropertyVectorEdit.h VtkTrackedCamera.h VtkVisPipeline.h - VtkVisPipelineItem.h VtkVisPipelineView.h VtkVisTabWidget.h ) @@ -87,6 +88,9 @@ SET( HEADERS VtkSurfacesSource.h VtkTextureOnSurfaceFilter.h VtkVisHelper.h + VtkVisImageItem.h + VtkVisPipelineItem.h + VtkVisPointSetItem.h ) # UI files @@ -140,6 +144,10 @@ ADD_LIBRARY( VtkVis STATIC TARGET_LINK_LIBRARIES( VtkVis ${QT_LIBRARIES} QVTK ) +IF(OGS_USE_VRPN) + INCLUDE_DIRECTORIES(../Vrpn) +ENDIF() # OGS_USE_VRPN + IF (OGS_USE_OPENSG) USE_OPENSG(VtkVis) INCLUDE_DIRECTORIES( ../OpenSG ) diff --git a/VtkVis/VisualizationWidget.cpp b/VtkVis/VisualizationWidget.cpp index 041da82ad19ba30bc7edfdb2c39610bf4b9f3f3b..e6221d0f3a59b447c35172b8f023c43819bdd825 100644 --- a/VtkVis/VisualizationWidget.cpp +++ b/VtkVis/VisualizationWidget.cpp @@ -7,7 +7,6 @@ // ** INCLUDES ** #include "VisualizationWidget.h" -#include "Configure.h" #include "Point.h" #include "VtkPickCallback.h" #include "VtkCustomInteractorStyle.h" diff --git a/VtkVis/VisualizationWidget.h b/VtkVis/VisualizationWidget.h index 6720c118f0d60c4b170f0f2263d9be9b9c979ca3..fe9195b58681ebfb42aedb3631b45cb0c010d852 100644 --- a/VtkVis/VisualizationWidget.h +++ b/VtkVis/VisualizationWidget.h @@ -10,7 +10,6 @@ // ** INCLUDES ** #include "ui_VisualizationWidgetBase.h" -#include "Configure.h" class vtkRenderer; class VtkCustomInteractorStyle; diff --git a/VtkVis/VtkAddFilterDialog.cpp b/VtkVis/VtkAddFilterDialog.cpp index 9ff8ad6f6d330a62f924e197153e95b49f56c9a2..4337b341ed2afff484945a7bc1ce0022ba028a6a 100644 --- a/VtkVis/VtkAddFilterDialog.cpp +++ b/VtkVis/VtkAddFilterDialog.cpp @@ -9,6 +9,8 @@ #include "VtkAddFilterDialog.h" #include "VtkVisPipeline.h" #include "VtkVisPipelineItem.h" +#include "VtkVisImageItem.h" +#include "VtkVisPointSetItem.h" #include "VtkCompositeFilter.h" #include "VtkFilterFactory.h" @@ -66,19 +68,24 @@ void VtkAddFilterDialog::on_buttonBox_accepted() itemData << filterListWidget->currentItem()->text() << true; VtkCompositeFilter* filter; - if (dynamic_cast<vtkImageAlgorithm*>(parentItem->algorithm())) + if (dynamic_cast<VtkVisImageItem*>(parentItem)) filter = VtkFilterFactory::CreateCompositeFilter(filterName, parentItem->algorithm()); else filter = VtkFilterFactory::CreateCompositeFilter(filterName, parentItem->transformFilter()); VtkVisPipelineItem* item; if (filter) - item = new VtkVisPipelineItem(filter, parentItem, itemData); + { + if (filter->GetOutputDataObjectType() == VTK_IMAGE_DATA) + item = new VtkVisImageItem(filter, parentItem, itemData); + else + item = new VtkVisPointSetItem(filter, parentItem, itemData); + } else { vtkAlgorithm* algorithm = VtkFilterFactory::CreateSimpleFilter(filterName); if (algorithm) - item = new VtkVisPipelineItem(algorithm, parentItem, itemData); + item = new VtkVisPointSetItem(algorithm, parentItem, itemData); else { std::cout << "Error: VtkFilterFavctory cannot create " << filterName.toStdString() << std::endl; diff --git a/VtkVis/VtkCompositeSelectionFilter.cpp b/VtkVis/VtkCompositeSelectionFilter.cpp index 1a40325c7ea9c4bf2f7a0a35520b17ad693959b5..55aa25eab853eb6fae2706304161b6df19e225b1 100644 --- a/VtkVis/VtkCompositeSelectionFilter.cpp +++ b/VtkVis/VtkCompositeSelectionFilter.cpp @@ -1,7 +1,7 @@ /** * \file VtkCompositeSelectionFilter.cpp * 2011/02/10 KR Initial implementation - * + * * Implementation of VtkCompositeSelectionFilter class */ @@ -22,7 +22,7 @@ VtkCompositeSelectionFilter::VtkCompositeSelectionFilter( vtkAlgorithm* inputAlg void VtkCompositeSelectionFilter::init() { - const char* filter_name = std::string("Selection").c_str(); + const char* filter_name("Selection"); double thresholdLower(0.0), thresholdUpper(1.0); this->_inputDataObjectType = VTK_UNSTRUCTURED_GRID; this->_outputDataObjectType = VTK_UNSTRUCTURED_GRID; diff --git a/VtkVis/VtkVisImageItem.cpp b/VtkVis/VtkVisImageItem.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49bf6243cf2d4b654409720382940a928784904a --- /dev/null +++ b/VtkVis/VtkVisImageItem.cpp @@ -0,0 +1,119 @@ +/** + * \file VtkVisImageItem.cpp + * 2011/09/29 KR Initial implementation + */ + +// ** INCLUDES ** +#include "VtkVisImageItem.h" +#include "VtkAlgorithmProperties.h" + +#include <vtkActor.h> +#include <vtkDataSetMapper.h> +#include "QVtkDataSetMapper.h" +#include <vtkImageAlgorithm.h> +#include <vtkRenderer.h> +#include <vtkSmartPointer.h> + +// export test +#include <vtkXMLImageDataWriter.h> +#include <vtkImageActor.h> + + +VtkVisImageItem::VtkVisImageItem( + vtkAlgorithm* algorithm, TreeItem* parentItem, + const QList<QVariant> data /*= QList<QVariant>()*/) +: VtkVisPipelineItem(algorithm, parentItem, data) +{ +} + +VtkVisImageItem::VtkVisImageItem( + VtkCompositeFilter* compositeFilter, TreeItem* parentItem, + const QList<QVariant> data /*= QList<QVariant>()*/) +: VtkVisPipelineItem(compositeFilter, parentItem, data) +{ +} + +VtkVisImageItem::~VtkVisImageItem() +{ +} + +void VtkVisImageItem::Initialize(vtkRenderer* renderer) +{ + _renderer = renderer; + _mapper = QVtkDataSetMapper::New(); + _mapper->InterpolateScalarsBeforeMappingOff(); + + // Use a special vtkImageActor instead of vtkActor + vtkImageAlgorithm* imageAlg = static_cast<vtkImageAlgorithm*>(_algorithm); + vtkImageActor* imageActor = vtkImageActor::New(); + imageActor->SetInput(imageAlg->GetOutput()); + _actor = imageActor; + _renderer->AddActor(_actor); + + // Set pre-set properties + VtkAlgorithmProperties* vtkProps = dynamic_cast<VtkAlgorithmProperties*>(_algorithm); + if (vtkProps) + setVtkProperties(vtkProps); +/* + // Copy properties from parent + else + { +*/ + VtkVisPipelineItem* parentItem = dynamic_cast<VtkVisPipelineItem*>(this->parentItem()); + while (parentItem) + { + VtkAlgorithmProperties* parentProps = dynamic_cast<VtkAlgorithmProperties*>(parentItem->algorithm()); + if (parentProps) + { + VtkAlgorithmProperties* newProps = new VtkAlgorithmProperties(); + newProps->SetScalarVisibility(parentProps->GetScalarVisibility()); + newProps->SetTexture(parentProps->GetTexture()); + setVtkProperties(newProps); + vtkProps = newProps; + parentItem = NULL; + } + else + parentItem = dynamic_cast<VtkVisPipelineItem*>(parentItem->parentItem()); + } +// } + + // Set active scalar to the desired one from VtkAlgorithmProperties + // or to match those of the parent. + if (vtkProps) + { + if (vtkProps->GetActiveAttribute().length() > 0) + { + this->SetActiveAttribute(vtkProps->GetActiveAttribute()); + } + else + { + VtkVisPipelineItem* visParentItem = dynamic_cast<VtkVisPipelineItem*>(this->parentItem()); + if (visParentItem) + this->SetActiveAttribute(visParentItem->GetActiveAttribute()); + if (vtkProps->GetTexture() != NULL) + this->SetActiveAttribute("Solid Color"); + } + } +} + +void VtkVisImageItem::setVtkProperties(VtkAlgorithmProperties* vtkProps) +{ + // todo implementation + (void)vtkProps; +} + +int VtkVisImageItem::callVTKWriter(vtkAlgorithm* algorithm, const std::string &filename) const +{ + vtkImageAlgorithm* algID = dynamic_cast<vtkImageAlgorithm*>(algorithm); + if (algID) + { + vtkSmartPointer<vtkXMLImageDataWriter> iWriter = vtkSmartPointer<vtkXMLImageDataWriter>::New(); + iWriter->SetInput(algID->GetOutputDataObject(0)); + std::string filenameWithExt = filename; + filenameWithExt.append(".vti"); + iWriter->SetFileName(filenameWithExt.c_str()); + return iWriter->Write(); + } + std::cout << "VtkVisPipelineItem::writeToFile() - Unknown data type..." << std::endl; + return 0; +} diff --git a/VtkVis/VtkVisImageItem.h b/VtkVis/VtkVisImageItem.h new file mode 100644 index 0000000000000000000000000000000000000000..e83a72643238227ca95b3be13bf7050d954e6eeb --- /dev/null +++ b/VtkVis/VtkVisImageItem.h @@ -0,0 +1,57 @@ +/** + * \file VtkVisImageItem.h + * 2011/09/29 KR Initial implementation + * + */ + + +#ifndef VTKVISIMAGEITEM_H +#define VTKVISIMAGEITEM_H + +// ** INCLUDES ** +#include "VtkVisPipelineItem.h" + +class vtkAlgorithm; +class vtkPointSet; +class QVtkDataSetMapper; +class vtkProp3D; +class vtkRenderer; +class VtkAlgorithmProperties; +class vtkOsgActor; +class VtkCompositeFilter; + +/** + * \brief An item in the VtkVisPipeline containing a graphic object to be visualized. + * + * Any VTK-object (source-items, filter-items, etc.) need to be put into a VtkPipelineItem + * to be assigned a mapper, an actor and its visualization properties (colour, etc.). + */ +class VtkVisImageItem : public VtkVisPipelineItem +{ + +public: + /// @brief Constructor for a source/filter object. + VtkVisImageItem(vtkAlgorithm* algorithm, + TreeItem* parentItem, + const QList<QVariant> data = QList<QVariant>()); + + /// @brief Constructor for composite filter + VtkVisImageItem(VtkCompositeFilter* compositeFilter, TreeItem* parentItem, + const QList<QVariant> data = QList<QVariant>()); + + ~VtkVisImageItem(); + + /// @brief Initializes vtkMapper and vtkActor necessary for visualization of + /// the item and sets the item's properties. + void Initialize(vtkRenderer* renderer); + +protected: + virtual int callVTKWriter(vtkAlgorithm* algorithm, const std::string &filename) const; + void setVtkProperties(VtkAlgorithmProperties* vtkProps); + +private: + +}; + +#endif // VTKVISIMAGEITEM_H + diff --git a/VtkVis/VtkVisPipeline.cpp b/VtkVis/VtkVisPipeline.cpp index dd005c21a366f8ad86de768a994cf8c77e0e8687..d0442d10c9994e12fbfe3bfdd3693982031e8b77 100644 --- a/VtkVis/VtkVisPipeline.cpp +++ b/VtkVis/VtkVisPipeline.cpp @@ -16,6 +16,8 @@ #include "ConditionModel.h" #include "StationTreeModel.h" #include "VtkVisPipelineItem.h" +#include "VtkVisImageItem.h" +#include "VtkVisPointSetItem.h" #include "VtkMeshSource.h" #include "VtkAlgorithmProperties.h" #include "VtkTrackedCamera.h" @@ -53,25 +55,6 @@ #include <QColor> #include <QSettings> -#ifdef OGS_USE_OPENSG -#include "vtkOsgActor.h" -VtkVisPipeline::VtkVisPipeline(vtkRenderer* renderer, OSG::SimpleSceneManager* manager, QObject* parent /*= 0*/) -: TreeModel(parent), _renderer(renderer), _sceneManager(manager) -{ - QList<QVariant> rootData; - rootData << "Object name" << "Visible"; - delete _rootItem; - _rootItem = new TreeItem(rootData, NULL); - VtkVisPipelineItem::rootNode = _sceneManager->getRoot(); - - QSettings settings("UFZ", "OpenGeoSys-5"); - QVariant backgroundColorVariant = settings.value("VtkBackgroundColor"); - if (backgroundColorVariant != QVariant()) - this->setBGColor(backgroundColorVariant.value<QColor>()); - - _resetCameraOnAddOrRemove = true; -} -#else // OGS_USE_OPENSG VtkVisPipeline::VtkVisPipeline( vtkRenderer* renderer, QObject* parent /*= 0*/ ) : TreeModel(parent), _renderer(renderer) { @@ -87,7 +70,6 @@ VtkVisPipeline::VtkVisPipeline( vtkRenderer* renderer, QObject* parent /*= 0*/ ) _resetCameraOnAddOrRemove = true; } -#endif // OGS_USE_OPENSG bool VtkVisPipeline::setData( const QModelIndex &index, const QVariant &value, int role /* = Qt::EditRole */ ) @@ -339,12 +321,11 @@ void VtkVisPipeline::addPipelineItem( vtkAlgorithm* source, itemName = QString(source->GetClassName()); itemData << itemName << true; - VtkVisPipelineItem* item = new VtkVisPipelineItem(source, parentItem, itemData); + VtkVisPipelineItem* item(NULL); + vtkImageAlgorithm* alg = dynamic_cast<vtkImageAlgorithm*>(source); + if (alg) item = new VtkVisImageItem(source, parentItem, itemData); + else item = new VtkVisPointSetItem(source, parentItem, itemData); this->addPipelineItem(item, parent); - -#ifdef OGS_USE_OPENSG - _sceneManager->showAll(); -#endif // OGS_USE_OPENSG } void VtkVisPipeline::removeSourceItem(GeoTreeModel* model, const std::string &name, GEOLIB::GEOTYPE type) @@ -477,7 +458,7 @@ void VtkVisPipeline::checkMeshQuality(VtkMeshSource* source, MshQualityType::typ VtkCompositeFilter* filter = VtkFilterFactory::CreateCompositeFilter("VtkCompositeSelectionFilter", parentItem->transformFilter()); static_cast<VtkCompositeSelectionFilter*>(filter)->setSelectionArray(quality); - VtkVisPipelineItem* item = new VtkVisPipelineItem(filter, parentItem, itemData); + VtkVisPointSetItem* item = new VtkVisPointSetItem(filter, parentItem, itemData); this->addPipelineItem(item, this->createIndex(i, 0, item)); } } diff --git a/VtkVis/VtkVisPipeline.h b/VtkVis/VtkVisPipeline.h index 6951ccdf167614be39d288eaf28f3233afb46c3c..6dc5e04b6c3f4a08ae08a072b03e303c56f95fd1 100644 --- a/VtkVis/VtkVisPipeline.h +++ b/VtkVis/VtkVisPipeline.h @@ -20,11 +20,6 @@ #include <QVector> #include <QMap> -#ifdef OGS_USE_OPENSG - #include <OpenSG/OSGSimpleSceneManager.h> -#endif // OGS_USE_OPENSG - - class vtkAlgorithm; class vtkDataSet; class vtkLight; @@ -51,13 +46,7 @@ class VtkVisPipeline : public TreeModel Q_OBJECT public: - - /// \brief Constructor -#ifdef OGS_USE_OPENSG - VtkVisPipeline(vtkRenderer* renderer, OSG::SimpleSceneManager* manager, QObject* parent = 0); -#else // OGS_USE_OPENSG VtkVisPipeline(vtkRenderer* renderer, QObject* parent = 0); -#endif // OGS_USE_OPENSG /// \brief Emits vtkVisPipelineChanged() and calls base class method. bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); @@ -126,12 +115,6 @@ private: QMap<vtkProp3D*, QModelIndex> _actorMap; bool _resetCameraOnAddOrRemove; -#ifdef OGS_USE_OPENSG - OSG::SimpleSceneManager* _sceneManager; -#endif // OGS_USE_OPENSG - - - signals: /// \brief Is emitted when a pipeline item was added or removed. void vtkVisPipelineChanged() const; diff --git a/VtkVis/VtkVisPipelineItem.cpp b/VtkVis/VtkVisPipelineItem.cpp index 9e4977abbb43d33af8e50283f004839d8a94badb..0d592d333ae7333db954d77546a9f63b1fcae2ad 100644 --- a/VtkVis/VtkVisPipelineItem.cpp +++ b/VtkVis/VtkVisPipelineItem.cpp @@ -17,133 +17,51 @@ #include <vtkRenderer.h> #include <vtkProperty.h> #include <vtkSmartPointer.h> -#include <vtkTransformFilter.h> -#include <vtkTransform.h> #include <vtkTextureMapToPlane.h> #include <vtkGenericDataObjectWriter.h> #include <QMessageBox> -#include <QObject> - -#ifdef OGS_USE_OPENSG -#include <OpenSG/OSGSceneFileHandler.h> -#include <OpenSG/OSGCoredNodePtr.h> -#include <OpenSG/OSGGroup.h> -#include <OpenSG/OSGNode.h> -#include "vtkOsgActor.h" -#endif - -// export test -#include <vtkPolyDataAlgorithm.h> -#include <vtkXMLPolyDataWriter.h> -#include <vtkUnstructuredGridAlgorithm.h> -#include <vtkXMLUnstructuredGridWriter.h> -#include <vtkXMLImageDataWriter.h> -#include <vtkImageActor.h> -#include <vtkImageAlgorithm.h> -#include <vtkTubeFilter.h> -#include <vtkTriangleFilter.h> #include "VtkCompositeFilter.h" #include <vtkPointData.h> #include <vtkCellData.h> -#include <vtkDataSetAttributes.h> #ifdef OGS_USE_OPENSG -OSG::NodePtr VtkVisPipelineItem::rootNode = NullFC; - - VtkVisPipelineItem::VtkVisPipelineItem( - vtkAlgorithm* algorithm, - TreeItem* parentItem, - const QList<QVariant> data /*= QList<QVariant>()*/) - : TreeItem(data, parentItem), _actor(NULL), _algorithm(algorithm), _mapper(NULL), _renderer(NULL), - _compositeFilter(NULL), _transformFilter(NULL), _activeAttribute("") - { - VtkVisPipelineItem* visParentItem = dynamic_cast<VtkVisPipelineItem*>(parentItem); - if (visParentItem) - { - _parentNode = static_cast<vtkOsgActor*>(visParentItem->actor())->GetOsgRoot(); - - if (parentItem->parentItem()) - { - if (dynamic_cast<vtkImageAlgorithm*>(visParentItem->algorithm())) - _algorithm->SetInputConnection(visParentItem->algorithm()->GetOutputPort()); - else - _algorithm->SetInputConnection(visParentItem->transformFilter()->GetOutputPort()); - } - } - else - _parentNode = rootNode; - } - - VtkVisPipelineItem::VtkVisPipelineItem( - VtkCompositeFilter* compositeFilter, TreeItem* parentItem, - const QList<QVariant> data /*= QList<QVariant>()*/ ) - : TreeItem(data, parentItem), _actor(NULL), _mapper(NULL), _renderer(NULL), - _compositeFilter(compositeFilter), _transformFilter(NULL), _activeAttribute("") - { - _algorithm = _compositeFilter->GetOutputAlgorithm(); - VtkVisPipelineItem* visParentItem = dynamic_cast<VtkVisPipelineItem*>(parentItem); - if (visParentItem) - _parentNode = static_cast<vtkOsgActor*>(visParentItem->actor())->GetOsgRoot(); - else - _parentNode = rootNode; - } +#include "vtkOsgConverter.h" +#include <OpenSG/OSGSceneFileHandler.h> +#endif -#else // OGS_USE_OPENSG - VtkVisPipelineItem::VtkVisPipelineItem( - vtkAlgorithm* algorithm, TreeItem* parentItem, - const QList<QVariant> data /*= QList<QVariant>()*/) - : TreeItem(data, parentItem), _actor(NULL), _algorithm(algorithm), _mapper(NULL), _renderer(NULL), - _compositeFilter(NULL), _transformFilter(NULL), _activeAttribute("") - { - VtkVisPipelineItem* visParentItem = dynamic_cast<VtkVisPipelineItem*>(parentItem); - if (parentItem->parentItem()) - { - if (dynamic_cast<vtkImageAlgorithm*>(visParentItem->algorithm())) - _algorithm->SetInputConnection(visParentItem->algorithm()->GetOutputPort()); - else - _algorithm->SetInputConnection(visParentItem->transformFilter()->GetOutputPort()); - } - } - VtkVisPipelineItem::VtkVisPipelineItem( - VtkCompositeFilter* compositeFilter, TreeItem* parentItem, - const QList<QVariant> data /*= QList<QVariant>()*/) - : TreeItem(data, parentItem), _actor(NULL), _mapper(NULL), _renderer(NULL), - _compositeFilter(compositeFilter), _transformFilter(NULL), _activeAttribute("") +VtkVisPipelineItem::VtkVisPipelineItem( + vtkAlgorithm* algorithm, TreeItem* parentItem, + const QList<QVariant> data /*= QList<QVariant>()*/) +: TreeItem(data, parentItem), _actor(NULL), _algorithm(algorithm), _mapper(NULL), _renderer(NULL), + _compositeFilter(NULL) +{ + VtkVisPipelineItem* visParentItem = dynamic_cast<VtkVisPipelineItem*>(parentItem); + if (parentItem->parentItem()) { - _algorithm = _compositeFilter->GetOutputAlgorithm(); + _algorithm->SetInputConnection(visParentItem->algorithm()->GetOutputPort()); } -#endif // OGS_USE_OPENSG +} +VtkVisPipelineItem::VtkVisPipelineItem( + VtkCompositeFilter* compositeFilter, TreeItem* parentItem, + const QList<QVariant> data /*= QList<QVariant>()*/) +: TreeItem(data, parentItem), _actor(NULL), _mapper(NULL), _renderer(NULL), + _compositeFilter(compositeFilter) +{ + _algorithm = _compositeFilter->GetOutputAlgorithm(); +} VtkVisPipelineItem::~VtkVisPipelineItem() { - #ifdef OGS_USE_OPENSG - vtkOsgActor* osgActor = dynamic_cast<vtkOsgActor*>(actor()); - if(_parentNode != NullFC) - { - OSG::beginEditCP(_parentNode);{ - OSG::RefPtr<OSG::NodePtr> node; - node = osgActor->GetOsgRoot(); - _parentNode->subChild(node); - };OSG::endEditCP(_parentNode); - } - _renderer->RemoveActor(osgActor); - _mapper->Delete(); - osgActor->Delete(); - #else // OGS_USE_OPENSG - _renderer->RemoveActor(_actor); - _mapper->Delete(); - _actor->Delete(); - //_algorithm->Delete(); // TODO: not calling delete causes memoryleak in some cases (e.g. building mesh from images), - // always calling it causes error when closing program - #endif // OGS_USE_OPENSG - delete _compositeFilter; - if (_transformFilter) _transformFilter->Delete(); + _renderer->RemoveActor(_actor); + _mapper->Delete(); + _actor->Delete(); + delete _compositeFilter; } VtkVisPipelineItem* VtkVisPipelineItem::child( int row ) const @@ -154,6 +72,7 @@ VtkVisPipelineItem* VtkVisPipelineItem::child( int row ) const else return NULL; } + QVariant VtkVisPipelineItem::data( int column ) const { if (column == 1) @@ -187,152 +106,6 @@ void VtkVisPipelineItem::setVisible( bool visible ) _renderer->Render(); } -void VtkVisPipelineItem::Initialize(vtkRenderer* renderer) -{ - _activeAttribute = ""; - - vtkImageAlgorithm* imageAlgorithm = dynamic_cast<vtkImageAlgorithm*>(_algorithm); - if (imageAlgorithm==NULL) // if algorithm is no image - { - - _transformFilter = vtkTransformFilter::New(); - vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New(); - transform->Identity(); - _transformFilter->SetTransform(transform); - - _transformFilter->SetInputConnection(_algorithm->GetOutputPort()); - _transformFilter->Update(); - } - - _renderer = renderer; - _mapper = QVtkDataSetMapper::New(); - _mapper->InterpolateScalarsBeforeMappingOff(); - - -#ifdef OGS_USE_OPENSG - _actor = vtkOsgActor::New(); - - // Transform vtkImageData to vtkPolyData for OpenSG-conversion - if (imageAlgorithm) - { - vtkSmartPointer<vtkTextureMapToPlane> toPolyData = - vtkSmartPointer<vtkTextureMapToPlane>::New(); - toPolyData->SetInputConnection(imageAlgorithm->GetOutputPort()); - _mapper->SetInputConnection(toPolyData->GetOutputPort()); - } - else - { - // vtkTubeFilter generates triangle strips. These are not handled correctly - // by the OpenSG converter. So the strips are converted to ordinary triangles. - vtkTubeFilter* tubeFilter = dynamic_cast<vtkTubeFilter*>(_algorithm); - if (tubeFilter) - { - vtkSmartPointer<vtkTriangleFilter> triangulate = - vtkSmartPointer<vtkTriangleFilter>::New(); - triangulate->SetInputConnection(_transformFilter->GetOutputPort()); - _mapper->SetInputConnection(triangulate->GetOutputPort()); - } - else - _mapper->SetInputConnection(_transformFilter->GetOutputPort()); - } - _actor->SetMapper(_mapper); - - OSG::beginEditCP(_parentNode);{ - _parentNode->addChild(_actor->GetOsgRoot()); - };OSG::endEditCP(_parentNode); -#else - - // Use a special vtkImageActor instead of vtkActor - if (imageAlgorithm) - { - vtkImageAlgorithm* imageAlg = static_cast<vtkImageAlgorithm*>(_algorithm); - vtkImageActor* imageActor = vtkImageActor::New(); - imageActor->SetInput(imageAlg->GetOutput()); - _actor = imageActor; - } - else - { - _mapper->SetInputConnection(_transformFilter->GetOutputPort()); - _actor = vtkActor::New(); - static_cast<vtkActor*>(_actor)->SetMapper(_mapper); - } -#endif - _renderer->AddActor(_actor); - - // Set pre-set properties - VtkAlgorithmProperties* vtkProps = dynamic_cast<VtkAlgorithmProperties*>(_algorithm); - if (vtkProps) - setVtkProperties(vtkProps); - - // Copy properties from parent - else - { - VtkVisPipelineItem* parentItem = dynamic_cast<VtkVisPipelineItem*>(this->parentItem()); - while (parentItem) - { - VtkAlgorithmProperties* parentProps = dynamic_cast<VtkAlgorithmProperties*>(parentItem->algorithm()); - if (parentProps) - { - VtkAlgorithmProperties* newProps = new VtkAlgorithmProperties(); - newProps->SetScalarVisibility(parentProps->GetScalarVisibility()); - newProps->SetTexture(parentProps->GetTexture()); - setVtkProperties(newProps); - vtkProps = newProps; - parentItem = NULL; - } - else - parentItem = dynamic_cast<VtkVisPipelineItem*>(parentItem->parentItem()); - } - } - - // Set active scalar to the desired one from VtkAlgorithmProperties - // or to match those of the parent. - if (vtkProps) - { - if (vtkProps->GetActiveAttribute().length() > 0) - { - this->SetActiveAttribute(vtkProps->GetActiveAttribute()); - } - else - { - VtkVisPipelineItem* visParentItem = dynamic_cast<VtkVisPipelineItem*>(this->parentItem()); - if (visParentItem) - this->SetActiveAttribute(visParentItem->GetActiveAttribute()); - if (vtkProps->GetTexture() != NULL) - this->SetActiveAttribute("Solid Color"); - } - } -} - -void VtkVisPipelineItem::setVtkProperties(VtkAlgorithmProperties* vtkProps) -{ - QObject::connect(vtkProps, SIGNAL(ScalarVisibilityChanged(bool)), - _mapper, SLOT(SetScalarVisibility(bool))); - - vtkImageAlgorithm* imageAlgorithm = dynamic_cast<vtkImageAlgorithm*>(_algorithm); - if (imageAlgorithm==NULL) - this->setLookupTableForActiveScalar(); - - vtkActor* actor = dynamic_cast<vtkActor*>(_actor); - if (actor) - { - if (vtkProps->GetTexture() != NULL) - { - vtkProps->SetScalarVisibility(false); - actor->GetProperty()->SetColor(1,1,1); // don't colorise textures - actor->SetTexture(vtkProps->GetTexture()); - } - else - { - vtkSmartPointer<vtkProperty> itemProperty = vtkProps->GetProperties(); - actor->SetProperty(itemProperty); - } - - if (!vtkProps->GetScalarVisibility()) - vtkProps->SetScalarVisibility(false); - } -} - int VtkVisPipelineItem::writeToFile(const std::string &filename) const { if (!filename.empty()) @@ -340,10 +113,9 @@ int VtkVisPipelineItem::writeToFile(const std::string &filename) const if (filename.substr(filename.size() - 4).find("os") != std::string::npos) { #ifdef OGS_USE_OPENSG - vtkOsgActor* osgActor = static_cast<vtkOsgActor*>(_actor); - osgActor->SetVerbose(true); - osgActor->UpdateOsg(); - OSG::SceneFileHandler::the().write(osgActor->GetOsgRoot(), filename.c_str()); + vtkOsgConverter osgConverter(static_cast<vtkActor*>(_actor)); + if(osgConverter.WriteAnActor()) + OSG::SceneFileHandler::the().write(osgConverter.GetOsgNode(), filename.c_str()); #else QMessageBox::warning(NULL, "Functionality not implemented", "Sorry but this program was not compiled with OpenSG support."); @@ -351,50 +123,19 @@ int VtkVisPipelineItem::writeToFile(const std::string &filename) const return 0; } - vtkAlgorithm* alg = this->algorithm(); - vtkPolyDataAlgorithm* algPD = dynamic_cast<vtkPolyDataAlgorithm*>(alg); - vtkUnstructuredGridAlgorithm* algUG = dynamic_cast<vtkUnstructuredGridAlgorithm*>(alg); - vtkImageAlgorithm* algI = dynamic_cast<vtkImageAlgorithm*>(alg); - if (algPD) - { -// vtkGenericDataObjectWriter* pdWriter = vtkGenericDataObjectWriter::New(); - vtkSmartPointer<vtkXMLPolyDataWriter> pdWriter = - vtkSmartPointer<vtkXMLPolyDataWriter>::New(); - pdWriter->SetInput(algPD->GetOutputDataObject(0)); - //pdWriter->SetDataModeToAscii(); - //pdWriter->SetCompressorTypeToNone(); - std::string filenameWithExt = filename; - filenameWithExt.append(".vtp"); - pdWriter->SetFileName(filenameWithExt.c_str()); - return pdWriter->Write(); - } - else if (algUG) - { - vtkSmartPointer<vtkXMLUnstructuredGridWriter> ugWriter = - vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New(); - ugWriter->SetInput(algUG->GetOutputDataObject(0)); - //ugWriter->SetDataModeToAscii(); - //ugWriter->SetCompressorTypeToNone(); - std::string filenameWithExt = filename; - filenameWithExt.append(".vtu"); - ugWriter->SetFileName(filenameWithExt.c_str()); - return ugWriter->Write(); - } - else if (algI) - { - vtkSmartPointer<vtkXMLImageDataWriter> iWriter = - vtkSmartPointer<vtkXMLImageDataWriter>::New(); - iWriter->SetInput(algI->GetOutputDataObject(0)); - std::string filenameWithExt = filename; - filenameWithExt.append(".vti"); - iWriter->SetFileName(filenameWithExt.c_str()); - return iWriter->Write(); - } - std::cout << "VtkVisPipelineItem::writeToFile() - Unknown data type..." << std::endl; + return callVTKWriter(this->algorithm(), filename); } return 0; } +int VtkVisPipelineItem::callVTKWriter(vtkAlgorithm* algorithm, const std::string &filename) const +{ + // needs to be implemented in derived classes! + (void)algorithm; + (void)filename; + return 0; +} + vtkProp3D* VtkVisPipelineItem::actor() const { return _actor; @@ -405,134 +146,14 @@ void VtkVisPipelineItem::SetScalarVisibility( bool on ) _mapper->SetScalarVisibility(on); } -void VtkVisPipelineItem::SetActiveAttribute( const QString& name ) -{ - // Get type by identifier - bool onPointData = true; - if (name.contains(QRegExp("^P-"))) - onPointData = true; - else if (name.contains(QRegExp("^C-"))) - onPointData = false; - else if (name.contains("Solid Color")) - { - _activeAttribute = "Solid Color"; - _mapper->ScalarVisibilityOff(); - return; - } - else - return; - - // Remove type identifier - std::string strippedName = QString(name).remove(0, 2).toStdString(); - const char* charName = strippedName.c_str(); - - vtkDataSet* dataSet = vtkDataSet::SafeDownCast(this->_algorithm->GetOutputDataObject(0)); - if (dataSet) - { - if (onPointData) - { - vtkPointData* pointData = dataSet->GetPointData(); - if(pointData) - { - if(setActiveAttributeOnData(pointData, strippedName)) - { - _algorithm->SetInputArrayToProcess(0,0,0,vtkDataObject::FIELD_ASSOCIATION_POINTS, charName); - _mapper->SetScalarModeToUsePointData(); - } - else - { - _activeAttribute = "Solid Color"; - _mapper->ScalarVisibilityOff(); - return; - } - } - } - else - { - vtkCellData* cellData = dataSet->GetCellData(); - if(cellData) - { - if(setActiveAttributeOnData(cellData, strippedName)) - { - _algorithm->SetInputArrayToProcess(0,0,0,vtkDataObject::FIELD_ASSOCIATION_CELLS, charName); - _mapper->SetScalarModeToUseCellData(); - } - else - { - _activeAttribute = "Solid Color"; - _mapper->ScalarVisibilityOff(); - return; - } - } - } - - _mapper->SetScalarRange(dataSet->GetScalarRange()); - this->setLookupTableForActiveScalar(); - _mapper->ScalarVisibilityOn(); - //_mapper->Update(); // KR: TODO - this is incredibly slow ... WHY??? - _activeAttribute = name; - } -} - -bool VtkVisPipelineItem::setActiveAttributeOnData(vtkDataSetAttributes* data, std::string& name) -{ - bool arrayFound = false; - for (int i = 0; i < data->GetNumberOfArrays() && !arrayFound; i++) - { - std::string arrayName = data->GetArrayName(i); - if(arrayName.compare(name) == 0) - arrayFound = true; - } - if(arrayFound) - { - data->SetActiveAttribute(name.c_str(), vtkDataSetAttributes::SCALARS); - return true; - } - else - return false; -} - -void VtkVisPipelineItem::setLookupTableForActiveScalar() -{ - VtkAlgorithmProperties* vtkProps = dynamic_cast<VtkAlgorithmProperties*>(_algorithm); - if (vtkProps) - { - QVtkDataSetMapper* mapper = dynamic_cast<QVtkDataSetMapper*>(_mapper); - if (mapper) - { - if (vtkProps->GetLookupTable(this->GetActiveAttribute()) == NULL) // default color table - { - vtkLookupTable* lut = vtkLookupTable::New(); - vtkProps->SetLookUpTable(GetActiveAttribute(), lut); - } - else // specific color table - { - _mapper->SetLookupTable(vtkProps->GetLookupTable(this->GetActiveAttribute())); - } - - _mapper->SetScalarRange(_transformFilter->GetOutput()->GetScalarRange()); - //_mapper->Update(); KR: not necessary?! - } - } -} - -void VtkVisPipelineItem::SetScalarRange(double min, double max) +void VtkVisPipelineItem::setScale(double x, double y, double z) const { - _mapper->SetScalarRange(min, max); - _mapper->Update(); + (void)x; (void)y, (void)z; } -void VtkVisPipelineItem::setScale(double x, double y, double z) const +void VtkVisPipelineItem::setTranslation(double x, double y, double z) const { - if (this->transformFilter()) - { - vtkTransform* transform = - static_cast<vtkTransform*>(this->transformFilter()->GetTransform()); - transform->Identity(); - transform->Scale(x, y, z); - this->transformFilter()->Modified(); - } - + (void)x; (void)y, (void)z; } void VtkVisPipelineItem::setScaleOnChildren(double x, double y, double z) const diff --git a/VtkVis/VtkVisPipelineItem.h b/VtkVis/VtkVisPipelineItem.h index c3b12ff16994f09d0ea148d68d0542dd6c4f413b..f14fda743ea2ce344e656de05c731092c331c511 100644 --- a/VtkVis/VtkVisPipelineItem.h +++ b/VtkVis/VtkVisPipelineItem.h @@ -18,11 +18,6 @@ #include <QString> #include <QVariant> -#ifdef OGS_USE_OPENSG - #include <OpenSG/OSGNode.h> - #include <OpenSG/OSGRefPtr.h> -#endif // OGS_USE_OPENSG - class vtkAlgorithm; class vtkPointSet; class QVtkDataSetMapper; @@ -61,7 +56,7 @@ public: /// @brief Initializes vtkMapper and vtkActor necessary for visualization of /// the item and sets the item's properties. - void Initialize(vtkRenderer* renderer); + virtual void Initialize(vtkRenderer* renderer) = 0; QVariant data(int column) const; bool setData(int column, const QVariant &value); @@ -72,6 +67,12 @@ public: /// @brief Returns the actor as vtkProp3D vtkProp3D* actor() const; + // Dummy for implementation in derived classes + virtual const QString GetActiveAttribute() const { return QString(""); } + + // Dummy for implementation in derived classes + virtual void SetActiveAttribute(const QString& str) { (void)str; }; + /// @brief Returns the mapper QVtkDataSetMapper* mapper() const { return _mapper; } @@ -87,53 +88,30 @@ public: /// @brief Writes this algorithm's vtkDataSet (i.e. vtkPolyData or vtkUnstructuredGrid) to a vtk-file. int writeToFile(const std::string &filename) const; - vtkTransformFilter* transformFilter() const { return _transformFilter; } - - /// @brief Sets the selected attribute array for the visualisation of the data set. - void SetActiveAttribute(const QString& name); - - void SetScalarRange(double min, double max); - - /// @brief Gets the last selected attribute. - const QString& GetActiveAttribute() const {return _activeAttribute; } - /// @brief Sets the geometry and data scaling. - void setScale(double x, double y, double z) const; + virtual void setScale(double x, double y, double z) const; + + /// @brief Translates the item in vis-space. + virtual void setTranslation(double x, double y, double z) const; + // Dummy for implementation in derived classes + virtual vtkTransformFilter* transformFilter() const { return NULL; } /// @brief Sets the geometry and date scaling recursively on all children of /// this item. void setScaleOnChildren(double x, double y, double z) const; -#ifdef OGS_USE_OPENSG - // HACK static rootNode is set by VtkVisPipeline constructor - /// Do not use this variable except in VtkVisPipeline constructor! - static OSG::NodePtr rootNode; - -protected: - vtkOsgActor* _actor; - OSG::RefPtr<OSG::NodePtr> _parentNode; -#else // OGS_USE_OPENSG protected: vtkProp3D* _actor; -#endif // OGS_USE_OPENSG vtkAlgorithm* _algorithm; QVtkDataSetMapper* _mapper; vtkRenderer* _renderer; VtkCompositeFilter* _compositeFilter; - vtkTransformFilter* _transformFilter; - QString _activeAttribute; - - /// Sets a color lookup table for the current scalar array. - void setLookupTableForActiveScalar(); - /// @brief Sets pre-set properties on vtkActor and on vtkMapper - void setVtkProperties(VtkAlgorithmProperties* vtkProps); + virtual int callVTKWriter(vtkAlgorithm* algorithm, const std::string &filename) const; void SetScalarVisibility(bool on); private: - /// @see SetActiveAttribute() - bool setActiveAttributeOnData(vtkDataSetAttributes* data, std::string& name); }; diff --git a/VtkVis/VtkVisPointSetItem.cpp b/VtkVis/VtkVisPointSetItem.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e7ca0600f89a8cc8ec06434eb21d3b63d1505564 --- /dev/null +++ b/VtkVis/VtkVisPointSetItem.cpp @@ -0,0 +1,338 @@ +/** + * \file VtkVisPointSetItem.cpp + * 2011/09/29 KR Initial implementation + */ + +// ** INCLUDES ** +#include "VtkVisPointSetItem.h" +#include "VtkAlgorithmProperties.h" + +#include <vtkActor.h> +#include <vtkCellData.h> +#include <vtkDataSetMapper.h> +#include "QVtkDataSetMapper.h" +#include <vtkImageAlgorithm.h> +#include <vtkPointData.h> +#include <vtkRenderer.h> +#include <vtkSmartPointer.h> +#include <vtkTransformFilter.h> +#include <vtkTransform.h> + +#include <QObject> +#include <QRegExp> + +// export test +#include <vtkPolyDataAlgorithm.h> +#include <vtkXMLPolyDataWriter.h> +#include <vtkUnstructuredGridAlgorithm.h> +#include <vtkXMLUnstructuredGridWriter.h> +#include <vtkTubeFilter.h> +#include <vtkTriangleFilter.h> + +#include <vtkDataSetAttributes.h> + + + VtkVisPointSetItem::VtkVisPointSetItem( + vtkAlgorithm* algorithm, TreeItem* parentItem, + const QList<QVariant> data /*= QList<QVariant>()*/) + : VtkVisPipelineItem(algorithm, parentItem, data), _transformFilter(NULL), _activeAttribute("") + { + VtkVisPipelineItem* visParentItem = dynamic_cast<VtkVisPipelineItem*>(parentItem); + if (parentItem->parentItem()) + { + if (dynamic_cast<vtkImageAlgorithm*>(visParentItem->algorithm())) + _algorithm->SetInputConnection(visParentItem->algorithm()->GetOutputPort()); + else + { + VtkVisPointSetItem* pointSetItem = dynamic_cast<VtkVisPointSetItem*>(parentItem); + if (pointSetItem) _algorithm->SetInputConnection(pointSetItem->transformFilter()->GetOutputPort()); + } + } + } + + VtkVisPointSetItem::VtkVisPointSetItem( + VtkCompositeFilter* compositeFilter, TreeItem* parentItem, + const QList<QVariant> data /*= QList<QVariant>()*/) + : VtkVisPipelineItem(compositeFilter, parentItem, data), _transformFilter(NULL), _activeAttribute("") + { + } + + +VtkVisPointSetItem::~VtkVisPointSetItem() +{ + _transformFilter->Delete(); +} + +void VtkVisPointSetItem::Initialize(vtkRenderer* renderer) +{ + _activeAttribute = ""; + _transformFilter = vtkTransformFilter::New(); + vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New(); + transform->Identity(); + _transformFilter->SetTransform(transform); + + _transformFilter->SetInputConnection(_algorithm->GetOutputPort()); + _transformFilter->Update(); + + _renderer = renderer; + _mapper = QVtkDataSetMapper::New(); + _mapper->InterpolateScalarsBeforeMappingOff(); + + + // Use a special vtkImageActor instead of vtkActor + _mapper->SetInputConnection(_transformFilter->GetOutputPort()); + _actor = vtkActor::New(); + static_cast<vtkActor*>(_actor)->SetMapper(_mapper); + _renderer->AddActor(_actor); + + // Set pre-set properties + VtkAlgorithmProperties* vtkProps = dynamic_cast<VtkAlgorithmProperties*>(_algorithm); + if (vtkProps) + setVtkProperties(vtkProps); + + // Copy properties from parent + else + { + VtkVisPipelineItem* parentItem = dynamic_cast<VtkVisPipelineItem*>(this->parentItem()); + while (parentItem) + { + VtkAlgorithmProperties* parentProps = dynamic_cast<VtkAlgorithmProperties*>(parentItem->algorithm()); + if (parentProps) + { + VtkAlgorithmProperties* newProps = new VtkAlgorithmProperties(); + newProps->SetScalarVisibility(parentProps->GetScalarVisibility()); + newProps->SetTexture(parentProps->GetTexture()); + setVtkProperties(newProps); + vtkProps = newProps; + parentItem = NULL; + } + else + parentItem = dynamic_cast<VtkVisPipelineItem*>(parentItem->parentItem()); + } + } + + // Set active scalar to the desired one from VtkAlgorithmProperties + // or to match those of the parent. + if (vtkProps) + { + if (vtkProps->GetActiveAttribute().length() > 0) + { + this->SetActiveAttribute(vtkProps->GetActiveAttribute()); + } + else + { + VtkVisPointSetItem* visParentItem = dynamic_cast<VtkVisPointSetItem*>(this->parentItem()); + if (visParentItem) + this->SetActiveAttribute(visParentItem->GetActiveAttribute()); + if (vtkProps->GetTexture() != NULL) + this->SetActiveAttribute("Solid Color"); + } + } +} + +void VtkVisPointSetItem::setVtkProperties(VtkAlgorithmProperties* vtkProps) +{ + QObject::connect(vtkProps, SIGNAL(ScalarVisibilityChanged(bool)), + _mapper, SLOT(SetScalarVisibility(bool))); + + this->setLookupTableForActiveScalar(); + + vtkActor* actor = dynamic_cast<vtkActor*>(_actor); + if (actor) + { + if (vtkProps->GetTexture() != NULL) + { + vtkProps->SetScalarVisibility(false); + actor->GetProperty()->SetColor(1,1,1); // don't colorise textures + actor->SetTexture(vtkProps->GetTexture()); + } + else + { + vtkSmartPointer<vtkProperty> itemProperty = vtkProps->GetProperties(); + actor->SetProperty(itemProperty); + } + + if (!vtkProps->GetScalarVisibility()) + vtkProps->SetScalarVisibility(false); + } +} + +int VtkVisPointSetItem::callVTKWriter(vtkAlgorithm* algorithm, const std::string &filename) const +{ + vtkPolyDataAlgorithm* algPD = dynamic_cast<vtkPolyDataAlgorithm*>(algorithm); + vtkUnstructuredGridAlgorithm* algUG = dynamic_cast<vtkUnstructuredGridAlgorithm*>(algorithm); + if (algPD) + { +// vtkGenericDataObjectWriter* pdWriter = vtkGenericDataObjectWriter::New(); + vtkSmartPointer<vtkXMLPolyDataWriter> pdWriter = vtkSmartPointer<vtkXMLPolyDataWriter>::New(); + pdWriter->SetInput(algPD->GetOutputDataObject(0)); + //pdWriter->SetDataModeToAscii(); + //pdWriter->SetCompressorTypeToNone(); + std::string filenameWithExt = filename; + filenameWithExt.append(".vtp"); + pdWriter->SetFileName(filenameWithExt.c_str()); + return pdWriter->Write(); + } + else if (algUG) + { + vtkSmartPointer<vtkXMLUnstructuredGridWriter> ugWriter = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New(); + ugWriter->SetInput(algUG->GetOutputDataObject(0)); + //ugWriter->SetDataModeToAscii(); + //ugWriter->SetCompressorTypeToNone(); + std::string filenameWithExt = filename; + filenameWithExt.append(".vtu"); + ugWriter->SetFileName(filenameWithExt.c_str()); + return ugWriter->Write(); + } + std::cout << "VtkVisPipelineItem::writeToFile() - Unknown data type..." << std::endl; + return 0; +} + + +void VtkVisPointSetItem::SetActiveAttribute( const QString& name ) +{ + // Get type by identifier + bool onPointData = true; + if (name.contains(QRegExp("^P-"))) + onPointData = true; + else if (name.contains(QRegExp("^C-"))) + onPointData = false; + else if (name.contains("Solid Color")) + { + _activeAttribute = "Solid Color"; + _mapper->ScalarVisibilityOff(); + return; + } + else + return; + + // Remove type identifier + std::string strippedName = QString(name).remove(0, 2).toStdString(); + const char* charName = strippedName.c_str(); + + vtkDataSet* dataSet = vtkDataSet::SafeDownCast(this->_algorithm->GetOutputDataObject(0)); + if (dataSet) + { + if (onPointData) + { + vtkPointData* pointData = dataSet->GetPointData(); + if(pointData) + { + if(setActiveAttributeOnData(pointData, strippedName)) + { + _algorithm->SetInputArrayToProcess(0,0,0,vtkDataObject::FIELD_ASSOCIATION_POINTS, charName); + _mapper->SetScalarModeToUsePointData(); + } + else + { + _activeAttribute = "Solid Color"; + _mapper->ScalarVisibilityOff(); + return; + } + } + } + else + { + vtkCellData* cellData = dataSet->GetCellData(); + if(cellData) + { + if(setActiveAttributeOnData(cellData, strippedName)) + { + _algorithm->SetInputArrayToProcess(0,0,0,vtkDataObject::FIELD_ASSOCIATION_CELLS, charName); + _mapper->SetScalarModeToUseCellData(); + } + else + { + _activeAttribute = "Solid Color"; + _mapper->ScalarVisibilityOff(); + return; + } + } + } + + _mapper->SetScalarRange(dataSet->GetScalarRange()); + this->setLookupTableForActiveScalar(); + _mapper->ScalarVisibilityOn(); + //_mapper->Update(); // KR: TODO - this is incredibly slow ... WHY??? + _activeAttribute = name; + } +} + +bool VtkVisPointSetItem::setActiveAttributeOnData(vtkDataSetAttributes* data, std::string& name) +{ + bool arrayFound = false; + for (int i = 0; i < data->GetNumberOfArrays() && !arrayFound; i++) + { + std::string arrayName = data->GetArrayName(i); + if(arrayName.compare(name) == 0) + arrayFound = true; + } + if(arrayFound) + { + data->SetActiveAttribute(name.c_str(), vtkDataSetAttributes::SCALARS); + return true; + } + else + return false; +} + +void VtkVisPointSetItem::setLookupTableForActiveScalar() +{ + VtkAlgorithmProperties* vtkProps = dynamic_cast<VtkAlgorithmProperties*>(_algorithm); + if (vtkProps) + { + QVtkDataSetMapper* mapper = dynamic_cast<QVtkDataSetMapper*>(_mapper); + if (mapper) + { + if (vtkProps->GetLookupTable(this->GetActiveAttribute()) == NULL) // default color table + { + vtkLookupTable* lut = vtkLookupTable::New(); + vtkProps->SetLookUpTable(GetActiveAttribute(), lut); + } + else // specific color table + { + _mapper->SetLookupTable(vtkProps->GetLookupTable(this->GetActiveAttribute())); + } + + _mapper->SetScalarRange(_transformFilter->GetOutput()->GetScalarRange()); + //_mapper->Update(); KR: not necessary?! + } + } +} + +void VtkVisPointSetItem::SetScalarRange(double min, double max) +{ + _mapper->SetScalarRange(min, max); + _mapper->Update(); +} + +void VtkVisPointSetItem::setScale(double x, double y, double z) const +{ + if (this->transformFilter()) + { + vtkTransform* transform = + static_cast<vtkTransform*>(this->transformFilter()->GetTransform()); + double* trans = transform->GetPosition(); + transform->Identity(); + transform->Scale(x, y, z); + transform->Translate(trans[0]/x, trans[1]/y, trans[2]/z); + this->transformFilter()->Modified(); + } + +} + +void VtkVisPointSetItem::setTranslation(double x, double y, double z) const +{ + if (this->transformFilter()) + { + vtkTransform* transform = + static_cast<vtkTransform*>(this->transformFilter()->GetTransform()); + double* scale = transform->GetScale(); + transform->Identity(); + transform->Scale(scale); + transform->Translate(x, y, z); + this->transformFilter()->Modified(); + } + +} + diff --git a/VtkVis/VtkVisPointSetItem.h b/VtkVis/VtkVisPointSetItem.h new file mode 100644 index 0000000000000000000000000000000000000000..c438f7321f7a0153635a4f892891811e7a216dac --- /dev/null +++ b/VtkVis/VtkVisPointSetItem.h @@ -0,0 +1,87 @@ +/** + * \file VtkVisPointSetItem.h + * 2011/09/29 KR Initial implementation + * + */ + + +#ifndef VTKVISPOINTSETITEM_H +#define VTKVISPOINTSETITEM_H + +// ** INCLUDES ** +#include "VtkVisPipelineItem.h" + +class vtkAlgorithm; +class vtkPointSet; +class QVtkDataSetMapper; +class vtkProp3D; +class vtkRenderer; +class VtkAlgorithmProperties; +class vtkOsgActor; +class VtkCompositeFilter; +class vtkTransformFilter; +class vtkDataSetAttributes; + +/** + * \brief An item in the VtkVisPipeline containing a graphic object to be visualized. + * + * Any VTK-object (source-items, filter-items, etc.) need to be put into a VtkPipelineItem + * to be assigned a mapper, an actor and its visualization properties (colour, etc.). + */ +class VtkVisPointSetItem : public VtkVisPipelineItem +{ +// Q_OBJECT + +public: + /// @brief Constructor for a source/filter object. + VtkVisPointSetItem(vtkAlgorithm* algorithm, + TreeItem* parentItem, + const QList<QVariant> data = QList<QVariant>()); + + /// @brief Constructor for composite filter + VtkVisPointSetItem(VtkCompositeFilter* compositeFilter, TreeItem* parentItem, + const QList<QVariant> data = QList<QVariant>()); + + ~VtkVisPointSetItem(); + + /// @brief Gets the last selected attribute. + const QString GetActiveAttribute() const {return _activeAttribute; } + + /// @brief Initializes vtkMapper and vtkActor necessary for visualization of + /// the item and sets the item's properties. + void Initialize(vtkRenderer* renderer); + + vtkTransformFilter* transformFilter() const { return _transformFilter; } + + /// @brief Sets the selected attribute array for the visualisation of the data set. + void SetActiveAttribute(const QString& name); + + void SetScalarRange(double min, double max); + + /// @brief Sets the geometry and data scaling. + void setScale(double x, double y, double z) const; + + /// @brief Translates the item in vis-space. + void setTranslation(double x, double y, double z) const; + +protected: + vtkTransformFilter* _transformFilter; + QString _activeAttribute; + + virtual int callVTKWriter(vtkAlgorithm* algorithm, const std::string &filename) const; + + /// Sets a color lookup table for the current scalar array. + void setLookupTableForActiveScalar(); + + /// @brief Sets pre-set properties on vtkActor and on vtkMapper + void setVtkProperties(VtkAlgorithmProperties* vtkProps); + + +private: + /// @see SetActiveAttribute() + bool setActiveAttributeOnData(vtkDataSetAttributes* data, std::string& name); + +}; + +#endif // VTKVISPOINTSETITEM_H + diff --git a/VtkVis/VtkVisTabWidget.cpp b/VtkVis/VtkVisTabWidget.cpp index f84bc6ed5d758202499388e7e4bfc41dd9d88175..15ff08b2b96353c4dafd0e784750134557c720a1 100644 --- a/VtkVis/VtkVisTabWidget.cpp +++ b/VtkVis/VtkVisTabWidget.cpp @@ -35,6 +35,10 @@ VtkVisTabWidget::VtkVisTabWidget( QWidget* parent /*= 0*/ ) this->scaleZ->setValidator(new QDoubleValidator(0, 100, 8, this)); + this->transX->setValidator(new QDoubleValidator(this)); + this->transY->setValidator(new QDoubleValidator(this)); + this->transZ->setValidator(new QDoubleValidator(this)); + connect(this->vtkVisPipelineView, SIGNAL(requestViewUpdate()), this, SIGNAL(requestViewUpdate())); @@ -56,33 +60,58 @@ void VtkVisTabWidget::setActiveItem( VtkVisPipelineItem* item ) if (actor) { actorPropertiesGroupBox->setEnabled(true); + transformTabWidget->setEnabled(true); vtkProperty* vtkProps = actor->GetProperty(); diffuseColorPickerButton->setColor(vtkProps->GetDiffuseColor()); visibleEdgesCheckBox->setChecked(vtkProps->GetEdgeVisibility()); edgeColorPickerButton->setColor(vtkProps->GetEdgeColor()); opacitySlider->setValue((int)(vtkProps->GetOpacity() * 100.0)); - vtkTransform* transform = - static_cast<vtkTransform*>(_item->transformFilter()->GetTransform()); - double scale[3]; - transform->GetScale(scale); - scaleZ->setText(QString::number(scale[2])); - + + vtkTransform* transform = static_cast<vtkTransform*>(_item->transformFilter()->GetTransform()); + if (transform) + { + double scale[3]; + transform->GetScale(scale); + double trans[3]; + transform->GetPosition(trans); + + //switch signals off for just filling in text-boxes after clicking on an item + this->scaleZ->blockSignals(true); + this->transX->blockSignals(true); + this->transY->blockSignals(true); + this->transZ->blockSignals(true); + this->scaleZ->setText(QString::number(scale[2])); + this->transX->setText(QString::number(trans[0]/scale[0])); + this->transY->setText(QString::number(trans[1]/scale[1])); + this->transZ->setText(QString::number(trans[2]/scale[2])); + this->scaleZ->blockSignals(false); + this->transX->blockSignals(false); + this->transY->blockSignals(false); + this->transZ->blockSignals(false); + //switch signals back on + } this->buildScalarArrayComboBox(_item); // Set to last active attribute - QString activeAttribute = item->GetActiveAttribute(); - for (int i = 0; i < this->activeScalarComboBox->count(); i++) + QString activeAttribute = _item->GetActiveAttribute(); + if (activeAttribute.length()>0) { - QString itemText = this->activeScalarComboBox->itemText(i); - if (itemText.compare(activeAttribute) == 0) + for (int i = 0; i < this->activeScalarComboBox->count(); i++) { - this->activeScalarComboBox->setCurrentIndex(i); - break; + QString itemText = this->activeScalarComboBox->itemText(i); + if (itemText.compare(activeAttribute) == 0) + { + this->activeScalarComboBox->setCurrentIndex(i); + break; + } } } } else + { actorPropertiesGroupBox->setEnabled(false); + transformTabWidget->setEnabled(false); + } this->buildProportiesDialog(item); @@ -110,6 +139,7 @@ void VtkVisTabWidget::setActiveItem( VtkVisPipelineItem* item ) else { actorPropertiesGroupBox->setEnabled(false); + transformTabWidget->setEnabled(false); this->activeScalarComboBox->clear(); } @@ -179,6 +209,22 @@ void VtkVisTabWidget::on_scaleZ_textChanged(const QString &text) } } +void VtkVisTabWidget::translateItem() +{ + bool okX(true), okY(true), okZ(true); + double trans[3]; + + trans[0] = transX->text().toDouble(&okX); + trans[1] = transY->text().toDouble(&okY); + trans[2] = transZ->text().toDouble(&okZ); + + if (okX && okY && okZ) + { + _item->setTranslation(trans[0], trans[1], trans[2]); + emit requestViewUpdate(); + } +} + void VtkVisTabWidget::buildProportiesDialog(VtkVisPipelineItem* item) { QFormLayout* layout = static_cast<QFormLayout*>(this->scrollAreaWidgetContents->layout()); diff --git a/VtkVis/VtkVisTabWidget.h b/VtkVis/VtkVisTabWidget.h index 513da64b2490be272a913e39392bca7c32b8c414..e3d35bb872add3a924d5ee3445e7573bd4a0deb1 100644 --- a/VtkVis/VtkVisTabWidget.h +++ b/VtkVis/VtkVisTabWidget.h @@ -15,7 +15,7 @@ class vtkAlgorithm; /** * \brief Contains a QTreeView of the VtkVisPipeline and a properties - * panel for adjusting vtkAlgorithms rendering and filter settings. + * panel for adjusting vtkAlgorithms rendering and filter settings. */ class VtkVisTabWidget : public QWidget, public Ui_VtkVisTabWidgetBase { @@ -34,6 +34,21 @@ protected slots: void on_edgeColorPickerButton_colorPicked(QColor color); void on_opacitySlider_sliderMoved(int value); void on_scaleZ_textChanged(const QString &text); + void on_transX_textChanged(const QString &text) + { + Q_UNUSED(text); + this->translateItem(); + }; + void on_transY_textChanged(const QString &text) + { + Q_UNUSED(text); + this->translateItem(); + }; + void on_transZ_textChanged(const QString &text) + { + Q_UNUSED(text); + this->translateItem(); + }; void SetActiveAttributeOnItem(const QString &name); @@ -43,6 +58,9 @@ private: /// Reads the scalar arrays of the given vtk-object and constructs content for the scalar array selection box. void buildScalarArrayComboBox(VtkVisPipelineItem* item); + + void translateItem(); + VtkVisPipelineItem* _item; signals: diff --git a/VtkVis/VtkVisTabWidgetBase.ui b/VtkVis/VtkVisTabWidgetBase.ui index 07be0bde26e78fbad680454f982d34b81b9578ae..5bad5ace50b77877336788fc9cc91a94414b79fb 100644 --- a/VtkVis/VtkVisTabWidgetBase.ui +++ b/VtkVis/VtkVisTabWidgetBase.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>279</width> - <height>741</height> + <width>259</width> + <height>677</height> </rect> </property> <property name="windowTitle"> @@ -55,7 +55,7 @@ <property name="minimumSize"> <size> <width>0</width> - <height>200</height> + <height>180</height> </size> </property> <property name="title"> @@ -113,23 +113,6 @@ </property> </widget> </item> - <item row="5" column="0"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>Scaling Factor</string> - </property> - </widget> - </item> - <item row="5" column="1"> - <widget class="QLineEdit" name="scaleZ"> - <property name="text"> - <string>1</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> <item row="1" column="1"> <widget class="QComboBox" name="activeScalarComboBox"/> </item> @@ -143,6 +126,183 @@ </layout> </widget> </item> + <item> + <widget class="QTabWidget" name="transformTabWidget"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>60</height> + </size> + </property> + <property name="currentIndex"> + <number>1</number> + </property> + <widget class="QWidget" name="scalingTab"> + <attribute name="title"> + <string>Scaling</string> + </attribute> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <property name="spacing"> + <number>5</number> + </property> + <property name="margin"> + <number>5</number> + </property> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <property name="spacing"> + <number>5</number> + </property> + <property name="sizeConstraint"> + <enum>QLayout::SetDefaultConstraint</enum> + </property> + <item> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Scaling Factor</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="scaleZ"> + <property name="text"> + <string>1</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <widget class="QWidget" name="translationTab"> + <attribute name="title"> + <string>Translation</string> + </attribute> + <layout class="QHBoxLayout" name="horizontalLayout_5"> + <property name="spacing"> + <number>5</number> + </property> + <property name="margin"> + <number>5</number> + </property> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <property name="spacing"> + <number>5</number> + </property> + <item> + <widget class="QLabel" name="transXLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>X</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="transX"> + <property name="text"> + <string>0</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="transYLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Y</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="transY"> + <property name="text"> + <string>0</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="transZLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Z</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="transZ"> + <property name="text"> + <string>0</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </widget> + </item> <item> <widget class="QGroupBox" name="filterPropertiesGroupBox"> <property name="sizePolicy">