Path: blob/devel/ElmerGUI/Application/vtkpost/featureedge.cpp
3203 views
/*****************************************************************************1* *2* Elmer, A Finite Element Software for Multiphysical Problems *3* *4* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *5* *6* This program is free software; you can redistribute it and/or *7* modify it under the terms of the GNU General Public License *8* as published by the Free Software Foundation; either version 2 *9* of the License, or (at your option) any later version. *10* *11* This program is distributed in the hope that it will be useful, *12* but WITHOUT ANY WARRANTY; without even the implied warranty of *13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *14* GNU General Public License for more details. *15* *16* You should have received a copy of the GNU General Public License *17* along with this program (in file fem/GPL-2); if not, write to the *18* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *19* Boston, MA 02110-1301, USA. *20* *21*****************************************************************************/2223/*****************************************************************************24* *25* ElmerGUI featureedge *26* *27*****************************************************************************28* *29* Authors: Mikko Lyly, Juha Ruokolainen and Peter R�back *30* Email: [email protected] *31* Web: http://www.csc.fi/elmer *32* Address: CSC - IT Center for Science Ltd. *33* Keilaranta 14 *34* 02101 Espoo, Finland *35* *36* Original Date: 15 Mar 2008 *37* *38*****************************************************************************/3940#include <QtGui>41#include <iostream>42#include "vtkpost.h"43#include "featureedge.h"44#include "preferences.h"4546#include <vtkGeometryFilter.h>47#include <vtkFeatureEdges.h>48#include <vtkPolyDataMapper.h>49#include <vtkProperty.h>50#include <vtkTubeFilter.h>51#include <vtkClipPolyData.h>52#include <vtkPlane.h>5354using namespace std;5556FeatureEdge::FeatureEdge(QWidget *parent)57: QDialog(parent)58{59ui.setupUi(this);6061setWindowTitle("Feature edges");62setWindowIcon(QIcon(":/icons/Mesh3D.png"));6364actor = vtkActor::New();65}6667FeatureEdge::~FeatureEdge()68{69actor->Delete();70}7172/*73// The original draw() function which draws all the groups by one FeatureEdge instance74// using one vtkUnstructuredGrid. This ends up with boundary of two groups not drawn.75void FeatureEdge::draw(VtkPost* vtkPost, Preferences* preferences)76{77bool useSurfaceGrid = preferences->ui.surfaceRButton->isChecked();78int featureAngle = preferences->ui.angleSpin->value();79int lineWidth = preferences->ui.lineWidthSpin->value();80bool useTubeFilter = preferences->ui.featureEdgeTubes->isChecked();81int tubeQuality = preferences->ui.featureEdgeTubeQuality->value();82int radius = preferences->ui.featureEdgeTubeRadius->value();83bool useClip = preferences->ui.featureEdgesClip->isChecked();84bool boundaryEdges = preferences->ui.drawBoundaryEdges->isChecked();85useClip |= vtkPost->GetClipAll();8687vtkUnstructuredGrid* grid = NULL;8889if(useSurfaceGrid) {90grid = vtkPost->GetSurfaceGrid();91} else {92grid = vtkPost->GetVolumeGrid();93}9495if(!grid) return;9697if(grid->GetNumberOfCells() < 1) return;9899// Convert from vtkUnstructuredGrid to vtkPolyData:100vtkGeometryFilter* filter = vtkGeometryFilter::New();101#if VTK_MAJOR_VERSION <= 5102filter->SetInput(grid);103#else104filter->SetInputData(grid);105#endif106// filter->GetOutput()->ReleaseDataFlagOn();107108vtkFeatureEdges* edges = vtkFeatureEdges::New();109edges->SetInputConnection(filter->GetOutputPort());110edges->SetFeatureAngle(featureAngle);111edges->NonManifoldEdgesOn();112edges->ManifoldEdgesOn();113if(boundaryEdges) {114edges->BoundaryEdgesOn();115} else {116edges->BoundaryEdgesOff();117}118119vtkTubeFilter* tubes = vtkTubeFilter::New();120if(useTubeFilter) {121double r = vtkPost->GetLength() * radius / 2000.0;122tubes->SetInputConnection(edges->GetOutputPort());123tubes->SetNumberOfSides(tubeQuality);124tubes->SetRadius(r);125}126127vtkClipPolyData* clipper = vtkClipPolyData::New();128if(useClip) {129if(useTubeFilter) {130clipper->SetInputConnection(tubes->GetOutputPort());131} else {132clipper->SetInputConnection(edges->GetOutputPort());133}134clipper->SetClipFunction(vtkPost->GetClipPlane());135clipper->GenerateClippedOutputOn();136}137138vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();139if(useClip) {140mapper->SetInputConnection(clipper->GetOutputPort());141} else {142if(useTubeFilter) {143mapper->SetInputConnection(tubes->GetOutputPort());144} else {145mapper->SetInputConnection(edges->GetOutputPort());146}147}148mapper->ScalarVisibilityOff();149mapper->SetResolveCoincidentTopologyToPolygonOffset();150// mapper->ImmediateModeRenderingOn();151152vtkPost->GetFeatureEdgeActor()->GetProperty()->SetLineWidth(lineWidth);153vtkPost->GetFeatureEdgeActor()->GetProperty()->SetColor(0, 0, 0);154vtkPost->GetFeatureEdgeActor()->SetMapper(mapper);155156157mapper->Delete();158clipper->Delete();159tubes->Delete();160edges->Delete();161filter->Delete();162}163*/164165166// The new draw() function which draws one group by one FeatureEdge instance167// using the specified vtkUnstructuredGrid to draw boundary of two groups.168void FeatureEdge::draw(VtkPost* vtkPost, Preferences* preferences, vtkUnstructuredGrid* grid)169{170bool useSurfaceGrid = preferences->ui.surfaceRButton->isChecked();171int featureAngle = preferences->ui.angleSpin->value();172int lineWidth = preferences->ui.lineWidthSpin->value();173bool useTubeFilter = preferences->ui.featureEdgeTubes->isChecked();174int tubeQuality = preferences->ui.featureEdgeTubeQuality->value();175int radius = preferences->ui.featureEdgeTubeRadius->value();176bool useClip = preferences->ui.featureEdgesClip->isChecked();177bool boundaryEdges = preferences->ui.drawBoundaryEdges->isChecked();178useClip |= vtkPost->GetClipAll();179QColor color = preferences->getFeatureEdgeColor();180181182if(!grid) return;183184if(grid->GetNumberOfCells() < 1) return;185186// Convert from vtkUnstructuredGrid to vtkPolyData:187vtkGeometryFilter* filter = vtkGeometryFilter::New();188#if VTK_MAJOR_VERSION <= 5189filter->SetInput(grid);190#else191filter->SetInputData(grid);192#endif193// filter->GetOutput()->ReleaseDataFlagOn();194195vtkFeatureEdges* edges = vtkFeatureEdges::New();196edges->SetInputConnection(filter->GetOutputPort());197edges->SetFeatureAngle(featureAngle);198edges->NonManifoldEdgesOn();199edges->ManifoldEdgesOn();200if(boundaryEdges) {201edges->BoundaryEdgesOn();202} else {203edges->BoundaryEdgesOff();204}205206vtkTubeFilter* tubes = vtkTubeFilter::New();207if(useTubeFilter) {208double r = vtkPost->GetLength() * radius / 2000.0;209tubes->SetInputConnection(edges->GetOutputPort());210tubes->SetNumberOfSides(tubeQuality);211tubes->SetRadius(r);212}213214vtkClipPolyData* clipper = vtkClipPolyData::New();215if(useClip) {216if(useTubeFilter) {217clipper->SetInputConnection(tubes->GetOutputPort());218} else {219clipper->SetInputConnection(edges->GetOutputPort());220}221clipper->SetClipFunction(vtkPost->GetClipPlane());222clipper->GenerateClippedOutputOn();223}224225vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();226if(useClip) {227mapper->SetInputConnection(clipper->GetOutputPort());228} else {229if(useTubeFilter) {230mapper->SetInputConnection(tubes->GetOutputPort());231} else {232mapper->SetInputConnection(edges->GetOutputPort());233}234}235mapper->ScalarVisibilityOff();236mapper->SetResolveCoincidentTopologyToPolygonOffset();237// mapper->ImmediateModeRenderingOn();238239actor->GetProperty()->SetLineWidth(lineWidth);240actor->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());241actor->SetMapper(mapper);242243mapper->Delete();244clipper->Delete();245tubes->Delete();246edges->Delete();247filter->Delete();248}249250void FeatureEdge::removeActorFrom(vtkRenderer* renderer){251renderer->RemoveActor(actor);252}253void FeatureEdge::addActorTo(vtkRenderer* renderer){254renderer->AddActor(actor);255}256257