Path: blob/devel/ElmerGUI/Application/vtkpost/meshedge.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 meshedge *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 "meshedge.h"44#include "preferences.h"4546#include <vtkUnstructuredGrid.h>47#include <vtkExtractEdges.h>48#include <vtkDataSetMapper.h>49#include <vtkProperty.h>50#include <vtkActor.h>51#include <vtkTubeFilter.h>52#include <vtkClipPolyData.h>53#include <vtkPlane.h>5455using namespace std;5657MeshEdge::MeshEdge(QWidget *parent)58: QDialog(parent)59{60ui.setupUi(this);6162setWindowTitle("Mesh edges");63setWindowIcon(QIcon(":/icons/Mesh3D.png"));64}6566MeshEdge::~MeshEdge()67{68}6970void MeshEdge::draw(VtkPost* vtkPost, Preferences* preferences)71{72bool useSurfaceGrid = preferences->ui.meshEdgesSurface->isChecked();73int lineWidth = preferences->ui.meshLineWidth->value();74bool useTubeFilter = preferences->ui.meshEdgeTubes->isChecked();75int quality = preferences->ui.meshEdgeTubeQuality->value();76int radius = preferences->ui.meshEdgeTubeRadius->value();77bool useClip = preferences->ui.meshEdgesClip->isChecked();78useClip |= vtkPost->GetClipAll();79QColor color = preferences->getMeshEdgeColor();8081vtkUnstructuredGrid* grid = NULL;8283if(useSurfaceGrid) {84grid = vtkPost->GetSurfaceGrid();85} else {86grid = vtkPost->GetVolumeGrid();87}8889if(!grid) return;9091if(grid->GetNumberOfCells() < 1) return;9293vtkExtractEdges* edges = vtkExtractEdges::New();94#if VTK_MAJOR_VERSION <= 595edges->SetInput(grid);96#else97edges->SetInputData(grid);98#endif99100vtkTubeFilter* tubes = vtkTubeFilter::New();101if(useTubeFilter) {102double r = vtkPost->GetLength() * radius / 2000.0;103tubes->SetInputConnection(edges->GetOutputPort());104tubes->SetNumberOfSides(quality);105tubes->SetRadius(r);106}107108vtkClipPolyData* clipper = vtkClipPolyData::New();109if(useClip) {110if(useTubeFilter) {111clipper->SetInputConnection(tubes->GetOutputPort());112} else {113clipper->SetInputConnection(edges->GetOutputPort());114}115clipper->SetClipFunction(vtkPost->GetClipPlane());116clipper->GenerateClippedOutputOn();117}118119vtkDataSetMapper* mapper = vtkDataSetMapper::New();120if(useClip) {121mapper->SetInputConnection(clipper->GetOutputPort());122} else {123if(useTubeFilter) {124mapper->SetInputConnection(tubes->GetOutputPort());125} else {126mapper->SetInputConnection(edges->GetOutputPort());127}128}129mapper->ScalarVisibilityOff();130mapper->SetResolveCoincidentTopologyToPolygonOffset();131// mapper->ImmediateModeRenderingOn();132133vtkPost->GetMeshEdgeActor()->GetProperty()->SetLineWidth(lineWidth);134vtkPost->GetMeshEdgeActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());135vtkPost->GetMeshEdgeActor()->SetMapper(mapper);136137mapper->Delete();138clipper->Delete();139tubes->Delete();140edges->Delete();141}142143144