Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
14a8f1ca
Commit
14a8f1ca
authored
Apr 14, 2010
by
Alexander Wiebel
Browse files
[ADD
#284
] saving of isosurface possible
parent
82161b79
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
28 deletions
+49
-28
src/modules/marchingCubes/WMMarchingCubes.cpp
src/modules/marchingCubes/WMMarchingCubes.cpp
+27
-19
src/modules/marchingCubes/WMMarchingCubes.h
src/modules/marchingCubes/WMMarchingCubes.h
+5
-3
src/modules/marchingCubes/test/WMMarchingCubes_test.h
src/modules/marchingCubes/test/WMMarchingCubes_test.h
+17
-6
No files found.
src/modules/marchingCubes/WMMarchingCubes.cpp
View file @
14a8f1ca
...
...
@@ -205,7 +205,14 @@ void WMMarchingCubes::properties()
m_useTextureProp
=
m_properties
->
addProperty
(
"Use Texture"
,
"Use texturing of the surface?"
,
false
);
m_surfaceColor
=
m_properties
->
addProperty
(
"Surface Color"
,
"Description."
,
WColor
(
0.3
,
0.3
,
0.3
,
1.0
)
);
m_surfaceColor
=
m_properties
->
addProperty
(
"Surface Color"
,
"Description."
,
WColor
(
0.5
,
0.5
,
0.5
,
1.0
)
);
m_savePropGroup
=
m_properties
->
addPropertyGroup
(
"Save Surface"
,
""
);
m_saveTriggerProp
=
m_savePropGroup
->
addProperty
(
"Do Save"
,
"Press!"
,
WPVBaseTypes
::
PV_TRIGGER_READY
);
m_saveTriggerProp
->
getCondition
()
->
subscribeSignal
(
boost
::
bind
(
&
WMMarchingCubes
::
save
,
this
)
);
m_meshFile
=
m_savePropGroup
->
addProperty
(
"Mesh File"
,
""
,
WKernel
::
getAppPathObject
()
);
}
void
WMMarchingCubes
::
generateSurfacePre
(
double
isoValue
)
...
...
@@ -456,22 +463,23 @@ void WMMarchingCubes::notifyTextureChange()
m_textureChanged
=
true
;
}
// TODO(wiebel): MC move this to a separate module in the future
bool
WMMarchingCubes
::
save
(
std
::
string
fileName
,
const
WTriangleMesh2
&
triMesh
)
const
bool
WMMarchingCubes
::
save
()
const
{
if
(
triMesh
.
vertSize
()
==
0
)
m_saveTriggerProp
->
set
(
WPVBaseTypes
::
PV_TRIGGER_READY
,
false
);
if
(
m_triMesh
->
vertSize
()
==
0
)
{
WLogger
::
getLogger
()
->
addLogMessage
(
"Will not write file that contains 0 vertices."
,
"Marching Cubes"
,
LL_ERROR
);
return
false
;
}
if
(
triMesh
.
triangleSize
()
==
0
)
if
(
m_
triMesh
->
triangleSize
()
==
0
)
{
WLogger
::
getLogger
()
->
addLogMessage
(
"Will not write file that contains 0 triangles."
,
"Marching Cubes"
,
LL_ERROR
);
return
false
;
}
const
char
*
c_file
=
fileName
.
c_str
();
const
char
*
c_file
=
m_meshFile
->
get
().
file_string
()
.
c_str
();
std
::
ofstream
dataFile
(
c_file
);
if
(
dataFile
)
...
...
@@ -480,7 +488,7 @@ bool WMMarchingCubes::save( std::string fileName, const WTriangleMesh2& triMesh
}
else
{
WLogger
::
getLogger
()
->
addLogMessage
(
"open file failed"
+
fileName
,
"Marching Cubes"
,
LL_ERROR
);
WLogger
::
getLogger
()
->
addLogMessage
(
"open file failed"
+
m_meshFile
->
get
().
file_string
()
,
"Marching Cubes"
,
LL_ERROR
);
return
false
;
}
...
...
@@ -493,10 +501,10 @@ bool WMMarchingCubes::save( std::string fileName, const WTriangleMesh2& triMesh
dataFile
<<
(
"DATASET UNSTRUCTURED_GRID
\n
"
);
wmath
::
WPosition
point
;
dataFile
<<
"POINTS "
<<
triMesh
.
vertSize
()
<<
" float
\n
"
;
for
(
size_t
i
=
0
;
i
<
triMesh
.
vertSize
();
++
i
)
dataFile
<<
"POINTS "
<<
m_
triMesh
->
vertSize
()
<<
" float
\n
"
;
for
(
size_t
i
=
0
;
i
<
m_
triMesh
->
vertSize
();
++
i
)
{
point
=
triMesh
.
getVertexAsPosition
(
i
);
point
=
m_
triMesh
->
getVertexAsPosition
(
i
);
if
(
!
(
myIsfinite
(
point
[
0
]
)
&&
myIsfinite
(
point
[
1
]
)
&&
myIsfinite
(
point
[
2
]
)
)
)
{
WLogger
::
getLogger
()
->
addLogMessage
(
"Will not write file from data that contains NAN or INF."
,
"Marching Cubes"
,
LL_ERROR
);
...
...
@@ -505,22 +513,22 @@ bool WMMarchingCubes::save( std::string fileName, const WTriangleMesh2& triMesh
dataFile
<<
point
[
0
]
<<
" "
<<
point
[
1
]
<<
" "
<<
point
[
2
]
<<
"
\n
"
;
}
dataFile
<<
"CELLS "
<<
triMesh
.
triangleSize
()
<<
" "
<<
triMesh
.
triangleSize
()
*
4
<<
"
\n
"
;
for
(
size_t
i
=
0
;
i
<
triMesh
.
triangleSize
();
++
i
)
dataFile
<<
"CELLS "
<<
m_
triMesh
->
triangleSize
()
<<
" "
<<
m_
triMesh
->
triangleSize
()
*
4
<<
"
\n
"
;
for
(
size_t
i
=
0
;
i
<
m_
triMesh
->
triangleSize
();
++
i
)
{
dataFile
<<
"3 "
<<
triMesh
.
getTriVertId0
(
i
)
<<
" "
<<
triMesh
.
getTriVertId1
(
i
)
<<
" "
<<
triMesh
.
getTriVertId2
(
i
)
<<
"
\n
"
;
dataFile
<<
"3 "
<<
m_
triMesh
->
getTriVertId0
(
i
)
<<
" "
<<
m_
triMesh
->
getTriVertId1
(
i
)
<<
" "
<<
m_
triMesh
->
getTriVertId2
(
i
)
<<
"
\n
"
;
}
dataFile
<<
"CELL_TYPES "
<<
triMesh
.
triangleSize
()
<<
"
\n
"
;
for
(
size_t
i
=
0
;
i
<
triMesh
.
triangleSize
();
++
i
)
dataFile
<<
"CELL_TYPES "
<<
m_
triMesh
->
triangleSize
()
<<
"
\n
"
;
for
(
size_t
i
=
0
;
i
<
m_
triMesh
->
triangleSize
();
++
i
)
{
dataFile
<<
"5
\n
"
;
}
dataFile
<<
"POINT_DATA "
<<
triMesh
.
vertSize
()
<<
"
\n
"
;
dataFile
<<
"POINT_DATA "
<<
m_
triMesh
->
vertSize
()
<<
"
\n
"
;
dataFile
<<
"SCALARS scalars float
\n
"
;
dataFile
<<
"LOOKUP_TABLE default
\n
"
;
for
(
size_t
i
=
0
;
i
<
triMesh
.
vertSize
();
++
i
)
for
(
size_t
i
=
0
;
i
<
m_
triMesh
->
vertSize
();
++
i
)
{
dataFile
<<
"0
\n
"
;
}
...
...
src/modules/marchingCubes/WMMarchingCubes.h
View file @
14a8f1ca
...
...
@@ -132,10 +132,8 @@ private:
/**
* Store the mesh in legacy vtk file format.
* \param fileName the file where the triMesh will be written to
* \param triMesh this mesh will be stored.
*/
bool
save
(
std
::
string
fileName
,
const
WTriangleMesh2
&
triMesh
)
const
;
bool
save
()
const
;
/**
* Load meshes saved with WMMarchingCubes::save
...
...
@@ -156,6 +154,10 @@ private:
WPropBool
m_useTextureProp
;
//!< Property indicating whether to use texturing with scalar data sets.
WPropColor
m_surfaceColor
;
//!< Property determining the color for the surface if no textures are displayed
WPropGroup
m_savePropGroup
;
//!< Property group containing properties needed for saving the mesh.
WPropTrigger
m_saveTriggerProp
;
//!< This property triggers the actual writing,
WPropFilename
m_meshFile
;
//!< The mesh will be written to this file.
/**
* True when textures haven changed.
*/
...
...
src/modules/marchingCubes/test/WMMarchingCubes_test.h
View file @
14a8f1ca
...
...
@@ -93,10 +93,15 @@ public:
void
testSaveZero
()
{
WMMarchingCubes
mc
;
WTriangleMesh2
triMesh
(
0
,
0
);
boost
::
shared_ptr
<
WTriangleMesh2
>
triMesh
(
new
WTriangleMesh2
(
0
,
0
)
);
mc
.
m_triMesh
=
triMesh
;
std
::
string
fileName
=
wiotools
::
tempFileName
();
mc
.
m_properties
=
boost
::
shared_ptr
<
WProperties
>
(
new
WProperties
(
"Properties"
,
"Module's properties"
)
);
mc
.
m_savePropGroup
=
mc
.
m_properties
->
addPropertyGroup
(
"Save Surface"
,
""
);
mc
.
m_meshFile
=
mc
.
m_savePropGroup
->
addProperty
(
"Mesh File"
,
""
,
boost
::
filesystem
::
path
(
fileName
.
c_str
()
)
);
mc
.
m_saveTriggerProp
=
mc
.
m_savePropGroup
->
addProperty
(
"Do Save"
,
"Press!"
,
WPVBaseTypes
::
PV_TRIGGER_READY
);
bool
result
=
mc
.
save
(
fileName
,
triMesh
);
bool
result
=
mc
.
save
();
TS_ASSERT_EQUALS
(
result
,
false
);
// should return false as we did not have any vertices or triangles.
TS_ASSERT
(
!
wiotools
::
fileExists
(
fileName
)
);
}
...
...
@@ -108,7 +113,8 @@ public:
{
WMMarchingCubes
mc
;
const
unsigned
int
nbPos
=
10
;
WTriangleMesh2
triMesh
(
nbPos
,
3
);
boost
::
shared_ptr
<
WTriangleMesh2
>
triMesh
(
new
WTriangleMesh2
(
nbPos
,
3
)
);
mc
.
m_triMesh
=
triMesh
;
std
::
vector
<
wmath
::
WPosition
>
vertices
(
0
);
for
(
unsigned
int
posId
=
0
;
posId
<
nbPos
;
++
posId
)
...
...
@@ -116,17 +122,22 @@ public:
double
x
=
posId
*
posId
+
3.4
;
double
y
=
posId
+
1
;
double
z
=
3.
/
static_cast
<
double
>
(
posId
);
// provide nan values by dividing with zero
triMesh
.
addVertex
(
x
,
y
,
z
);
triMesh
->
addVertex
(
x
,
y
,
z
);
}
std
::
string
fileName
=
wiotools
::
tempFileName
();
mc
.
m_properties
=
boost
::
shared_ptr
<
WProperties
>
(
new
WProperties
(
"Properties"
,
"Module's properties"
)
);
mc
.
m_savePropGroup
=
mc
.
m_properties
->
addPropertyGroup
(
"Save Surface"
,
""
);
mc
.
m_meshFile
=
mc
.
m_savePropGroup
->
addProperty
(
"Mesh File"
,
""
,
boost
::
filesystem
::
path
(
fileName
.
c_str
()
)
);
mc
.
m_saveTriggerProp
=
mc
.
m_savePropGroup
->
addProperty
(
"Do Save"
,
"Press!"
,
WPVBaseTypes
::
PV_TRIGGER_READY
);
mc
.
save
(
fileName
,
triMesh
);
mc
.
save
();
bool
result
=
mc
.
save
(
fileName
,
triMesh
);
bool
result
=
mc
.
save
();
TS_ASSERT_EQUALS
(
result
,
false
);
// should return false as we did not have all coordinates values finite.
TS_ASSERT
(
!
wiotools
::
fileExists
(
fileName
)
);
}
// TODO(wiebel): reactivate these when schurade has reactivated loading
// /**
// * Test reading of surfaces
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment