OpenWalnut  1.5.0dev
WMWriteMesh_test.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WMWRITEMESH_TEST_H
26 #define WMWRITEMESH_TEST_H
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 #include <cxxtest/TestSuite.h>
33 
34 #include "../WMWriteMesh.h"
35 #include "core/common/WIOTools.h"
36 #include "core/common/WLogger.h"
37 #include "core/common/math/linearAlgebra/WPosition.h"
38 #include "core/graphicsEngine/WTriangleMesh.h"
39 
40 /**
41  * Test for WMWriteMesh
42  */
43 class WMWriteMeshTest : public CxxTest::TestSuite
44 {
45 public:
46  /**
47  * Setup method called before every test case.
48  */
49  void setUp()
50  {
52  }
53 
54  /**
55  * Ensure instatiation does not throw and does initialization right.
56  */
58  {
59  TS_ASSERT_THROWS_NOTHING( WMWriteMesh() );
60  }
61 
62  /**
63  * Test rejection of surfaces with zero triangles or vertices for save
64  */
65  void testSaveZero()
66  {
67  WMWriteMesh mc;
68  std::shared_ptr< WTriangleMesh > triMesh( new WTriangleMesh( 0, 0 ) );
69  mc.m_triMesh = triMesh;
70  std::string fileName = tempFilename().string();
71  mc.m_properties = std::shared_ptr< WProperties >( new WProperties( "Properties", "Module's properties" ) );
72  mc.m_savePropGroup = mc.m_properties->addPropertyGroup( "Save Surface", "" );
73  mc.m_meshFile = mc.m_savePropGroup->addProperty( "Mesh file", "", boost::filesystem::path( fileName.c_str() ) );
74  mc.m_saveTriggerProp = mc.m_savePropGroup->addProperty( "Do save", "Press!", WPVBaseTypes::PV_TRIGGER_READY );
75 
76  bool result = mc.saveVTKASCII();
77  TS_ASSERT_EQUALS( result, false ); // should return false as we did not have any vertices or triangles.
78  TS_ASSERT( !fileExists( fileName ) );
79  }
80 
81  /**
82  * Test rejection of surfaces with nan or inf in coordinates for save
83  */
85  {
86  WMWriteMesh mc;
87  const unsigned int nbPos = 10;
88  std::shared_ptr< WTriangleMesh > triMesh( new WTriangleMesh( nbPos, 3 ) );
89  mc.m_triMesh = triMesh;
90 
91  std::vector< WPosition > vertices( 0 );
92  for( unsigned int posId = 0; posId < nbPos; ++posId )
93  {
94  double x = posId * posId + 3.4;
95  double y = posId + 1;
96  double z = 3. / static_cast< double >( posId ); // provide nan values by dividing with zero
97  triMesh->addVertex( x, y, z );
98  }
99 
100  std::string fileName = tempFilename().string();
101  mc.m_properties = std::shared_ptr< WProperties >( new WProperties( "Properties", "Module's properties" ) );
102  mc.m_savePropGroup = mc.m_properties->addPropertyGroup( "Save Surface", "" );
103  mc.m_meshFile = mc.m_savePropGroup->addProperty( "Mesh file", "", boost::filesystem::path( fileName.c_str() ) );
104  mc.m_saveTriggerProp = mc.m_savePropGroup->addProperty( "Do save", "Press!", WPVBaseTypes::PV_TRIGGER_READY );
105 
106  mc.saveVTKASCII();
107 
108  bool result = mc.saveVTKASCII();
109  TS_ASSERT_EQUALS( result, false ); // should return false as we did not have all coordinates values finite.
110  TS_ASSERT( !fileExists( fileName ) );
111  }
112 };
113 
114 #endif // WMWRITEMESH_TEST_H
static void startup(std::ostream &output=std::cout, LogLevel level=LL_DEBUG)
Create the first and only instance of the logger as it is a singleton.
Definition: WLogger.cpp:41
Test for WMWriteMesh.
void testInstatiation()
Ensure instatiation does not throw and does initialization right.
void testSaveInfinteNan()
Test rejection of surfaces with nan or inf in coordinates for save.
void testSaveZero()
Test rejection of surfaces with zero triangles or vertices for save.
void setUp()
Setup method called before every test case.
This module writes the triangle mesh given at its input connector as a VTK ASCII file or ....
Definition: WMWriteMesh.h:46
bool saveVTKASCII() const
Store the mesh in legacy vtk file format.
WPropFilename m_meshFile
The mesh will be written to this file.
Definition: WMWriteMesh.h:142
std::shared_ptr< WTriangleMesh > m_triMesh
A pointer to the currently processed tri mesh.
Definition: WMWriteMesh.h:138
WPropTrigger m_saveTriggerProp
This property triggers the actual writing,.
Definition: WMWriteMesh.h:141
WPropGroup m_savePropGroup
Property group containing properties needed for saving the mesh.
Definition: WMWriteMesh.h:140
std::shared_ptr< WProperties > m_properties
The property object for the module.
Definition: WModule.h:640
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
Triangle mesh data structure allowing for convenient access of the elements.
Definition: WTriangleMesh.h:46
@ PV_TRIGGER_READY
Trigger property: is ready to be triggered (again)