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
85f2cc5a
Commit
85f2cc5a
authored
Dec 02, 2009
by
Mathias Goldau
Browse files
[ADD
#157
] Saving of DLtLookUpTable now possible
parent
b7e0ef8b
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
286 additions
and
40 deletions
+286
-40
src/dataHandler/io/WWriter.cpp
src/dataHandler/io/WWriter.cpp
+44
-0
src/dataHandler/io/WWriter.h
src/dataHandler/io/WWriter.h
+61
-0
src/dataHandler/io/WWriterFiberVTK.cpp
src/dataHandler/io/WWriterFiberVTK.cpp
+5
-15
src/dataHandler/io/WWriterFiberVTK.h
src/dataHandler/io/WWriterFiberVTK.h
+9
-17
src/dataHandler/io/WWriterLookUpTableVTK.cpp
src/dataHandler/io/WWriterLookUpTableVTK.cpp
+67
-0
src/dataHandler/io/WWriterLookUpTableVTK.h
src/dataHandler/io/WWriterLookUpTableVTK.h
+59
-0
src/modules/fiberClustering/WDXtLookUpTable.cpp
src/modules/fiberClustering/WDXtLookUpTable.cpp
+16
-0
src/modules/fiberClustering/WDXtLookUpTable.h
src/modules/fiberClustering/WDXtLookUpTable.h
+17
-1
src/modules/fiberClustering/WMFiberClustering.cpp
src/modules/fiberClustering/WMFiberClustering.cpp
+3
-0
src/modules/fiberCulling/WMFiberCulling.cpp
src/modules/fiberCulling/WMFiberCulling.cpp
+5
-7
No files found.
src/dataHandler/io/WWriter.cpp
0 → 100644
View file @
85f2cc5a
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <string>
#include "WWriter.h"
#include "WIOTools.hpp"
#include "../exceptions/WDHIOFailure.h"
WWriter
::
WWriter
(
std
::
string
fname
,
bool
overwrite
)
:
m_overwrite
(
overwrite
)
{
setFileName
(
fname
);
// not in constructor list since fileExcsits check
}
void
WWriter
::
setFileName
(
std
::
string
fname
)
{
m_fname
=
fname
;
if
(
!
m_overwrite
&&
wiotools
::
fileExists
(
m_fname
)
)
{
throw
WDHIOFailure
(
"File '"
+
m_fname
+
"' already exists, skip writing"
);
}
}
src/dataHandler/io/WWriter.h
0 → 100644
View file @
85f2cc5a
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WWRITER_H
#define WWRITER_H
#include <string>
/**
* Writes some data to a file. This class is only for convenience access to
* rudimentary file management things such as: file exists, if the given
* file should be overwritten, etc. Subclasses may use those mechanisms in
* their own public memberfunctions where the signature is different every
* time. e.g. writeFibs( WDataSetFibers ds );
*/
class
WWriter
{
public:
/**
* Creates a writer object for writing something to a file. Use the flags
* to specify the behaviour.
*
* \param fname path to the target file where stuff will be written to
* \param overwrite If true existing files will be overwritten
*/
WWriter
(
std
::
string
fname
,
bool
overwrite
=
false
);
/**
* Reset the destination (file) where the writing should take place.
*/
void
setFileName
(
std
::
string
fname
);
protected:
std
::
string
m_fname
;
//!< Absolute path of the file to write to
bool
m_overwrite
;
//!< flag indicating if the file may be overwritten (true) or not (false)
private:
};
#endif // WWRITER_H
src/dataHandler/io/WWriterVTK.cpp
→
src/dataHandler/io/WWriter
Fiber
VTK.cpp
View file @
85f2cc5a
...
...
@@ -28,27 +28,17 @@
#include <boost/shared_ptr.hpp>
#include "WWriterVTK.h"
#include "WWriter
Fiber
VTK.h"
#include "WIOTools.hpp"
#include "../WDataSetFibers.h"
#include "../exceptions/WDHIOFailure.h"
WWriterVTK
::
WWriterVTK
(
std
::
string
fname
,
bool
overwrite
)
:
m_overwrite
(
overwrite
)
WWriter
Fiber
VTK
::
WWriter
Fiber
VTK
(
std
::
string
fname
,
bool
overwrite
)
:
WWriter
(
fname
,
overwrite
)
{
setFileName
(
fname
);
}
void
WWriterVTK
::
setFileName
(
std
::
string
fname
)
{
m_fname
=
fname
;
if
(
!
m_overwrite
&&
wiotools
::
fileExists
(
m_fname
)
)
{
throw
WDHIOFailure
(
"File '"
+
m_fname
+
"' already exists, skip writing"
);
}
}
void
WWriterVTK
::
writeFibs
(
boost
::
shared_ptr
<
const
WDataSetFibers
>
fiberDS
)
const
void
WWriterFiberVTK
::
writeFibs
(
boost
::
shared_ptr
<
const
WDataSetFibers
>
fiberDS
)
const
{
using
std
::
fstream
;
fstream
out
(
m_fname
.
c_str
(),
fstream
::
out
|
fstream
::
in
|
fstream
::
trunc
);
...
...
@@ -56,7 +46,7 @@ void WWriterVTK::writeFibs( boost::shared_ptr< const WDataSetFibers > fiberDS )
{
throw
WDHIOFailure
(
"Invalid file, or permission: "
+
m_fname
);
}
out
<<
"#
vtk
DataFile Version 3.0"
<<
std
::
endl
;
out
<<
"#
VTK
DataFile Version 3.0"
<<
std
::
endl
;
out
<<
"Fibers from OpenWalnut"
<<
std
::
endl
;
out
<<
"BINARY"
<<
std
::
endl
;
out
<<
"DATASET POLYDATA"
<<
std
::
endl
;
...
...
src/dataHandler/io/WWriterVTK.h
→
src/dataHandler/io/WWriter
Fiber
VTK.h
View file @
85f2cc5a
...
...
@@ -22,32 +22,27 @@
//
//---------------------------------------------------------------------------
#ifndef WWRITERVTK_H
#define WWRITERVTK_H
#ifndef WWRITER
FIBER
VTK_H
#define WWRITER
FIBER
VTK_H
#include <string>
#include <boost/shared_ptr.hpp>
#include "../WDataSetFibers.h"
#include "WWriter.h"
/**
* Writes a VTK file.
* Writes a
Fiber
VTK file.
*/
class
WWriter
VTK
class
WWriter
FiberVTK
:
public
WWriter
{
public:
/**
* Creates a writer object for VTK file writing.
*
* \param fname absolute file name
* Creates a writer object for FiberVTK file writing. On parameter documentation
* take a look into the WWriter class.
*/
explicit
WWriterVTK
(
std
::
string
fname
,
bool
overwrite
=
false
);
/**
* Reset the destination (file) where the writing should take place.
*/
void
setFileName
(
std
::
string
fname
);
WWriterFiberVTK
(
std
::
string
fname
,
bool
overwrite
=
false
);
/**
* Writes a WDataSetFibers down to the previousely given file
...
...
@@ -55,10 +50,7 @@ public:
void
writeFibs
(
boost
::
shared_ptr
<
const
WDataSetFibers
>
fiberDS
)
const
;
protected:
private:
std
::
string
m_fname
;
//!< Absolute path of the file to write to
bool
m_overwrite
;
//!< flag indicating if the file may be overwritten (true) or not (false)
};
#endif // WWRITERVTK_H
#endif // WWRITER
FIBER
VTK_H
src/dataHandler/io/WWriterLookUpTableVTK.cpp
0 → 100644
View file @
85f2cc5a
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <cassert>
#include <fstream>
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include "WWriterLookUpTableVTK.h"
#include "WIOTools.hpp"
#include "../exceptions/WDHIOFailure.h"
WWriterLookUpTableVTK
::
WWriterLookUpTableVTK
(
std
::
string
fname
,
bool
overwrite
)
:
WWriter
(
fname
,
overwrite
)
{
}
void
WWriterLookUpTableVTK
::
writeTable
(
const
std
::
vector
<
double
>
&
table
)
const
{
using
std
::
fstream
;
fstream
out
(
m_fname
.
c_str
(),
fstream
::
out
|
fstream
::
in
|
fstream
::
trunc
);
if
(
!
out
||
out
.
bad
()
)
{
throw
WDHIOFailure
(
"Invalid file, or permission: "
+
m_fname
);
}
out
<<
"# vtk DataFile Version 3.0"
<<
std
::
endl
;
out
<<
"DXtLookUpTable from OpenWalnut"
<<
std
::
endl
;
out
<<
"BINARY"
<<
std
::
endl
;
out
<<
"FIELD DXtLookUpTable 1"
<<
std
::
endl
;
unsigned
int
numDistances
=
table
.
size
();
out
<<
"DISTANCES "
<<
numDistances
<<
" 1 float"
<<
std
::
endl
;
float
*
data
=
new
float
[
numDistances
];
for
(
size_t
i
=
0
;
i
<
numDistances
;
++
i
)
{
data
[
i
]
=
static_cast
<
float
>
(
table
[
i
]
);
}
wiotools
::
switchByteOrderOfArray
<
float
>
(
data
,
numDistances
);
out
.
write
(
reinterpret_cast
<
char
*
>
(
data
),
sizeof
(
float
)
*
numDistances
);
out
<<
std
::
endl
;
out
.
close
();
}
src/dataHandler/io/WWriterLookUpTableVTK.h
0 → 100644
View file @
85f2cc5a
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WWRITERLOOKUPTABLEVTK_H
#define WWRITERLOOKUPTABLEVTK_H
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include "WWriter.h"
/**
* Can write a look up table to a file in VTK format.
*/
class
WWriterLookUpTableVTK
:
public
WWriter
{
public:
/**
* Creates a writer object for FiberVTK file writing. On parameter documentation
* take a look into the WWriter class.
*/
WWriterLookUpTableVTK
(
std
::
string
fname
,
bool
overwrite
=
false
);
/**
* Actually perform writing to file.
*
* \param table The data in that table will be saved
* \param dim the dimensionality of the table
*/
void
writeTable
(
const
std
::
vector
<
double
>
&
table
)
const
;
protected:
private:
};
#endif // WWRITERLOOKUPTABLEVTK_H
src/modules/fiberClustering/WDXtLookUpTable.cpp
View file @
85f2cc5a
...
...
@@ -24,6 +24,7 @@
#include <cassert>
#include <algorithm>
#include <vector>
#include "WDXtLookUpTable.h"
...
...
@@ -42,3 +43,18 @@ double& WDXtLookUpTable::operator()( size_t i, size_t j )
}
return
_data
.
at
(
i
*
_dim
+
j
-
(
i
+
1
)
*
(
i
+
2
)
/
2
);
}
size_t
WDXtLookUpTable
::
size
()
const
{
return
_data
.
size
();
}
size_t
WDXtLookUpTable
::
dim
()
const
{
return
_dim
;
}
const
std
::
vector
<
double
>&
WDXtLookUpTable
::
getData
()
const
{
return
_data
;
}
src/modules/fiberClustering/WDXtLookUpTable.h
View file @
85f2cc5a
...
...
@@ -52,9 +52,25 @@ public:
*/
double
&
operator
()(
size_t
i
,
size_t
j
);
/**
* \return the number of distances inside this table.
*/
size_t
size
()
const
;
/**
* \return the dimensionality of this table
*/
size_t
dim
()
const
;
/**
* \return readonly access to the internal data
*/
const
std
::
vector
<
double
>&
getData
()
const
;
private:
/**
* Internal data structure to store the elements.
* Internal data structure to store the elements. The order is line major
* meaning first element (0,0)...(0,n-1),(1,0)...(1, n-1)...
*/
std
::
vector
<
double
>
_data
;
...
...
src/modules/fiberClustering/WMFiberClustering.cpp
View file @
85f2cc5a
...
...
@@ -42,6 +42,7 @@
#include "../../dataHandler/WDataHandler.h"
#include "../../dataHandler/WSubject.h"
#include "../../dataHandler/WDataSetFibers.h"
#include "../../dataHandler/io/WWriterLookUpTableVTK.h"
#include "../../kernel/WKernel.h"
#include "../../utils/WColorUtils.h"
...
...
@@ -195,6 +196,8 @@ void WMFiberClustering::cluster()
std
::
cout
<<
"Using "
<<
m_clusters
.
size
()
<<
" clusters."
;
m_lastFibsSize
=
m_fibs
->
size
();
WWriterLookUpTableVTK
w
(
"/tmp/pansen.dist"
,
true
);
w
.
writeTable
(
m_dLtTable
->
getData
()
);
}
osg
::
ref_ptr
<
osg
::
Geode
>
WMFiberClustering
::
genFiberGeode
(
const
WFiberCluster
&
cluster
,
const
WColor
color
)
const
...
...
src/modules/fiberCulling/WMFiberCulling.cpp
View file @
85f2cc5a
...
...
@@ -39,7 +39,7 @@
#include "../../dataHandler/WDataHandler.h"
#include "../../dataHandler/WSubject.h"
#include "../../dataHandler/WDataSetFibers.h"
#include "../../dataHandler/io/WWriterVTK.h"
#include "../../dataHandler/io/WWriter
Fiber
VTK.h"
#include "../../kernel/WKernel.h"
#include "../../utils/WColorUtils.h"
...
...
@@ -143,10 +143,8 @@ void WMFiberCulling::cullOutFibers( boost::shared_ptr< WDataSetFibers > fibers )
std
::
cout
<<
"Erasing done."
<<
std
::
endl
;
std
::
cout
<<
"Culled out "
<<
numFibers
-
fibers
->
size
()
<<
" fibers"
<<
std
::
endl
;
std
::
cout
<<
"There are "
<<
fibers
->
size
()
<<
" fibers left."
<<
std
::
endl
;
if
(
true
)
{
WWriterVTK
w
(
"/tmp/pansen"
,
true
);
w
.
writeFibs
(
fibers
);
// std::cout << "Saved fibers left from culling to " << << " done." << std::endl;
}
// TODO(math): make saving parameter dependent, and apply the desired path for saving
WWriterFiberVTK
w
(
"/tmp/pansen.fib"
,
true
);
w
.
writeFibs
(
fibers
);
}
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