Path: blob/devel/ElmerGUI/Application/vtkpost/meshpoint.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 meshpoint *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 "meshpoint.h"44#include "preferences.h"4546#include <vtkUnstructuredGrid.h>47#include <vtkSphereSource.h>48#include <vtkGlyph3D.h>49#include <vtkPolyDataMapper.h>50#include <vtkProperty.h>51#include <vtkActor.h>52#include <vtkClipPolyData.h>53#include <vtkPlane.h>5455using namespace std;5657MeshPoint::MeshPoint(QWidget *parent)58: QDialog(parent)59{60ui.setupUi(this);6162setWindowTitle("Mesh points");63setWindowIcon(QIcon(":/icons/Mesh3D.png"));64}6566MeshPoint::~MeshPoint()67{68}6970void MeshPoint::draw(VtkPost* vtkPost, Preferences* preferences)71{72double length = vtkPost->GetLength();73int pointQuality = preferences->ui.pointQuality->value();74int pointSize = preferences->ui.pointSize->value();75bool useSurfaceGrid = preferences->ui.meshPointsSurface->isChecked();76bool useClip = preferences->ui.meshPointsClip->isChecked();77useClip |= vtkPost->GetClipAll();78QColor color = preferences->getMeshPointColor();7980vtkSphereSource* sphere = vtkSphereSource::New();81sphere->SetRadius((double)pointSize * length / 2000.0);82sphere->SetThetaResolution(pointQuality);83sphere->SetPhiResolution(pointQuality);8485vtkUnstructuredGrid* grid = NULL;8687if(useSurfaceGrid) {88grid = vtkPost->GetSurfaceGrid();89} else {90grid = vtkPost->GetVolumeGrid();91}9293if(!grid) return;9495if(grid->GetNumberOfPoints() < 1) return;9697vtkGlyph3D* glyph = vtkGlyph3D::New();98#if VTK_MAJOR_VERSION <= 599glyph->SetInput(grid);100#else101glyph->SetInputData(grid);102#endif103glyph->SetSourceConnection(sphere->GetOutputPort());104105vtkClipPolyData* clipper = vtkClipPolyData::New();106if(useClip) {107clipper->SetInputConnection(glyph->GetOutputPort());108clipper->SetClipFunction(vtkPost->GetClipPlane());109clipper->GenerateClippedOutputOn();110}111112vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();113if(useClip) {114mapper->SetInputConnection(clipper->GetOutputPort());115} else {116mapper->SetInputConnection(glyph->GetOutputPort());117}118mapper->ScalarVisibilityOff();119120vtkPost->GetMeshPointActor()->SetMapper(mapper);121vtkPost->GetMeshPointActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());122123mapper->Delete();124clipper->Delete();125glyph->Delete();126sphere->Delete();127}128129130