Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
OpenWalnut Core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
44
Issues
44
List
Boards
Labels
Service Desk
Milestones
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
7679c99c
Commit
7679c99c
authored
Jul 20, 2012
by
Sebastian Eichelbaum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADD
#194
] TF exporter module. Exports transfer functions in simple txt format
parent
a299326f
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
386 additions
and
2 deletions
+386
-2
src/core/common/WStringUtils.h
src/core/common/WStringUtils.h
+15
-0
src/core/kernel/WModuleInputData.h
src/core/kernel/WModuleInputData.h
+10
-0
src/core/kernel/WModuleOutputData.h
src/core/kernel/WModuleOutputData.h
+10
-0
src/modules/modules-io.toolbox
src/modules/modules-io.toolbox
+1
-0
src/modules/transferFunction1D/WMTransferFunction1D.h
src/modules/transferFunction1D/WMTransferFunction1D.h
+2
-2
src/modules/writeTransferFunction/WMWriteTransferFunction.cpp
...modules/writeTransferFunction/WMWriteTransferFunction.cpp
+171
-0
src/modules/writeTransferFunction/WMWriteTransferFunction.h
src/modules/writeTransferFunction/WMWriteTransferFunction.h
+111
-0
src/modules/writeTransferFunction/resources/META
src/modules/writeTransferFunction/resources/META
+66
-0
src/modules/writeTransferFunction/resources/WMWriteTransferFunction.png
...iteTransferFunction/resources/WMWriteTransferFunction.png
+0
-0
No files found.
src/core/common/WStringUtils.h
View file @
7679c99c
...
...
@@ -124,6 +124,21 @@ namespace string_utils
return
ss
.
str
();
}
/**
* Convert a given value to a string. The input value must provide a operator<< or be a standard scalar type.
*
* \param value the value to cast to string
*
* \return the string.
*/
inline
std
::
string
toString
(
const
unsigned
char
&
value
)
// NOLINT: stylechecker complains about non const ref!?
{
std
::
stringstream
ss
;
// NOTE: unsigned chars are interpreted as ASCII chars. We want it to be used as number.
ss
<<
static_cast
<
int
>
(
value
);
return
ss
.
str
();
}
/**
* Convert a given value to a string. The input value must provide a operator<< or be a standard scalar type. This method additionally allows
* setting width and precision flags of the used std::stringstream.
...
...
src/core/kernel/WModuleInputData.h
View file @
7679c99c
...
...
@@ -53,6 +53,16 @@ public:
*/
typedef
boost
::
shared_ptr
<
WModuleInputData
<
T
>
>
PtrType
;
/**
* Pointer to this. For convenience.
*/
typedef
boost
::
shared_ptr
<
WModuleInputData
<
T
>
>
SPtr
;
/**
* Pointer to this. For convenience.
*/
typedef
boost
::
shared_ptr
<
const
WModuleInputData
<
T
>
>
ConstSPtr
;
/**
* Reference to this type.
*/
...
...
src/core/kernel/WModuleOutputData.h
View file @
7679c99c
...
...
@@ -52,6 +52,16 @@ public:
*/
typedef
boost
::
shared_ptr
<
WModuleOutputData
<
T
>
>
PtrType
;
/**
* Pointer to this. For convenience.
*/
typedef
boost
::
shared_ptr
<
WModuleOutputData
<
T
>
>
SPtr
;
/**
* Pointer to this. For convenience.
*/
typedef
boost
::
shared_ptr
<
const
WModuleOutputData
<
T
>
>
ConstSPtr
;
/**
* Reference to this type.
*/
...
...
src/modules/modules-io.toolbox
View file @
7679c99c
...
...
@@ -6,3 +6,4 @@ ADD_MODULE( writeDendrogram )
ADD_MODULE( writeGeometry )
ADD_MODULE( writeMesh )
ADD_MODULE( writeTracts )
ADD_MODULE( writeTransferFunction )
src/modules/transferFunction1D/WMTransferFunction1D.h
View file @
7679c99c
...
...
@@ -105,12 +105,12 @@ private:
* An input connector used to get datasets from other modules. The connection management between co
nnectors must not be handled by the module.
*/
boost
::
shared_ptr
<
WModuleInputData
<
WDataSetSingle
>
>
m_input
;
WModuleInputData
<
WDataSetSingle
>::
SPtr
m_input
;
/**
* The output connector used to provide the calculated data to other modules.
*/
boost
::
shared_ptr
<
WModuleOutputData
<
WDataSetSingle
>
>
m_output
;
WModuleOutputData
<
WDataSetSingle
>::
SPtr
m_output
;
/**
* A condition used to notify about changes in several properties.
...
...
src/modules/writeTransferFunction/WMWriteTransferFunction.cpp
0 → 100644
View file @
7679c99c
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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/>.
//
//---------------------------------------------------------------------------
// C headers
// ...
// C++ headers
#include <fstream>
#include <string>
// External lib headers
#include <boost/shared_ptr.hpp>
// OW core headers
#include <core/common/WAssert.h>
#include <core/common/WPropertyHelper.h>
#include <core/common/WPathHelper.h>
#include <core/common/WStringUtils.h>
// own, local headers
#include "WMWriteTransferFunction.h"
W_LOADABLE_MODULE
(
WMWriteTransferFunction
)
WMWriteTransferFunction
::
WMWriteTransferFunction
()
:
WModule
()
{
}
WMWriteTransferFunction
::~
WMWriteTransferFunction
()
{
// cleanup
}
boost
::
shared_ptr
<
WModule
>
WMWriteTransferFunction
::
factory
()
const
{
// See "src/modules/template/" for an extensively documented example.
return
boost
::
shared_ptr
<
WModule
>
(
new
WMWriteTransferFunction
()
);
}
const
std
::
string
WMWriteTransferFunction
::
getName
()
const
{
return
"Write Transfer Function"
;
}
const
std
::
string
WMWriteTransferFunction
::
getDescription
()
const
{
// Specify your module description here. Be detailed. This text is read by the user.
return
"Allows to export transfer functions in several formats."
;
}
void
WMWriteTransferFunction
::
connectors
()
{
// an output connector for the transfer function created
m_input
=
WModuleInputData
<
WDataSetSingle
>::
createAndAdd
(
shared_from_this
(),
"transferFunction1D"
,
"The transfer function"
);
// call WModule's initialization
WModule
::
connectors
();
}
void
WMWriteTransferFunction
::
properties
()
{
m_propCondition
=
boost
::
shared_ptr
<
WCondition
>
(
new
WCondition
()
);
m_savePath
=
m_properties
->
addProperty
(
"Save Location"
,
"Set the path to the file."
,
WPathHelper
::
getAppPath
()
/
"tf.txt"
);
m_saveTrigger
=
m_properties
->
addProperty
(
"Save"
,
"Save to file."
,
WPVBaseTypes
::
PV_TRIGGER_READY
,
m_propCondition
);
// Call parent method
WModule
::
properties
();
}
void
WMWriteTransferFunction
::
moduleMain
()
{
m_moduleState
.
setResetable
(
true
,
true
);
m_moduleState
.
add
(
m_propCondition
);
m_moduleState
.
add
(
m_input
->
getDataChangedCondition
()
);
ready
();
// lets go
while
(
!
m_shutdownFlag
()
)
{
m_saveTrigger
->
set
(
WPVBaseTypes
::
PV_TRIGGER_READY
);
m_moduleState
.
wait
();
if
(
m_shutdownFlag
()
)
{
break
;
}
if
(
m_saveTrigger
->
get
(
true
)
==
WPVBaseTypes
::
PV_TRIGGER_TRIGGERED
)
{
WDataSetSingle
::
SPtr
d
=
m_input
->
getData
();
// valid data?
if
(
!
d
)
{
warnLog
()
<<
"No data available to save."
;
continue
;
}
// valid path?
boost
::
filesystem
::
path
p
=
m_savePath
->
get
(
true
);
debugLog
()
<<
"Save TF to
\"
"
+
p
.
string
()
+
"
\"
."
;
std
::
ofstream
f
;
f
.
open
(
p
.
string
().
c_str
()
);
if
(
!
f
.
good
()
)
{
errorLog
()
<<
"Failed to open file. Abort."
;
continue
;
}
// get value set and write it
boost
::
shared_ptr
<
WValueSetBase
>
vsb
=
d
->
getValueSet
();
if
(
(
vsb
->
order
()
!=
1
)
||
(
vsb
->
dimension
()
!=
4
)
||
(
vsb
->
getDataType
()
!=
W_DT_UNSIGNED_CHAR
)
)
{
errorLog
()
<<
"This is not a proper TF. Abort."
;
continue
;
}
// we ensured that the valuesetbase is this valueset:
boost
::
shared_ptr
<
WValueSet
<
unsigned
char
>
>
vs
=
boost
::
shared_dynamic_cast
<
WValueSet
<
unsigned
char
>
>
(
vsb
);
f
<<
"Exported using OpenWalnut. http://www.openwalnut.org"
<<
std
::
endl
;
f
<<
"# TF export format:"
<<
std
::
endl
<<
"# Comments begin with #"
<<
std
::
endl
<<
"# 1st line: width height"
<<
std
::
endl
<<
"# Then, RGBA quadruples; line-wise; values space separated; in x direction first."
<<
std
::
endl
;
// later, we might support 2d TFs. Now, write 1 as second dimension
f
<<
string_utils
::
toString
(
vs
->
size
()
)
<<
" "
<<
"1"
<<
std
::
endl
;
// go through each RGBA vector
for
(
size_t
i
=
0
;
i
<
vs
->
size
();
++
i
)
{
f
<<
string_utils
::
toString
(
vs
->
getScalar
(
i
*
4
+
0
)
)
<<
" "
<<
string_utils
::
toString
(
vs
->
getScalar
(
i
*
4
+
1
)
)
<<
" "
<<
string_utils
::
toString
(
vs
->
getScalar
(
i
*
4
+
2
)
)
<<
" "
<<
string_utils
::
toString
(
vs
->
getScalar
(
i
*
4
+
3
)
)
<<
std
::
endl
;
}
// done.
f
.
close
();
// done
m_saveTrigger
->
set
(
WPVBaseTypes
::
PV_TRIGGER_READY
);
}
}
}
src/modules/writeTransferFunction/WMWriteTransferFunction.h
0 → 100644
View file @
7679c99c
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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 WMMYNEWMODULE_H
#define WMMYNEWMODULE_H
#include <string>
#include <core/kernel/WModule.h>
#include <core/kernel/WModuleOutputData.h>
#include <core/kernel/WModuleInputData.h>
#include <core/common/WProperties.h>
/**
* Module to export transferfunctions
*
* \ingroup modules
*/
class
WMWriteTransferFunction
:
public
WModule
{
public:
/**
* Constructor.
*/
WMWriteTransferFunction
();
/**
* Destructor
*/
virtual
~
WMWriteTransferFunction
();
/**
* Gives back the name of this module.
* \return the module's name.
*/
virtual
const
std
::
string
getName
()
const
;
/**
* Gives back a description of this module.
* \return description to module.
*/
virtual
const
std
::
string
getDescription
()
const
;
/**
* Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
* should never be initialized or modified in some other way. A simple new instance is required.
*
* \return the prototype used to create every module in OpenWalnut.
*/
virtual
boost
::
shared_ptr
<
WModule
>
factory
()
const
;
protected:
/**
* Entry point after loading the module. Runs in separate thread.
*/
virtual
void
moduleMain
();
/**
* Initialize the connectors this module is using.
*/
virtual
void
connectors
();
/**
* Initialize the properties for this module.
*/
virtual
void
properties
();
private:
/**
* Condition used throughout the module to notify the thread if some changes happened (like properties have changed and similar).
*/
boost
::
shared_ptr
<
WCondition
>
m_propCondition
;
/**
* The connector used to get the TF.
*/
WModuleInputData
<
WDataSetSingle
>::
SPtr
m_input
;
/**
* Where to save the file to
*/
WPropFilename
m_savePath
;
/**
* DO the save operation
*/
WPropTrigger
m_saveTrigger
;
};
#endif // WMMYNEWMODULE_H
src/modules/writeTransferFunction/resources/META
0 → 100644
View file @
7679c99c
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------
// Provide additional material and descriptions for your module. You can
// provide this for multiple modules if you like.
// NOTE: everything but the module name is optional, even if this makes no
// sense at all.
// This defines some properties of the module "Template". This must
// match the name specified in WMTemplate::getName().
"Write Transfer Function"
{
// Provide an icon. If the icon exists, it overrides the one provided by your
// getIcon method. This path is relative to your module's resource directory.
icon="WMTransferFunction.png";
// Where to find the module?
website = "http://www.openwalnut.org";
// Provide a description, If you do so, this description overrides the one
// provided by your getDescription method.
// HINT: multi-line strings are not supported. Please provide long texts in
// one line.
description = "This module allows you to write transfer functions to disk.";
// Help file. This should be an HTML or TXT document. Only one document allowed.
// Provide a list of authors. These authors can have further information associated with them.
author = "OpenWalnut Project";
// Provide author information. Especially a contact address is very handy.
// This associates some URL and Mail contact info to "OpenWalnut Project".
"OpenWalnut Project"
{
url="http://www.openwalnut.org";
email="contact@openwalnut.org";
what="Design, Development and Bug fixing";
};
// Provide some tags to have modules nicely grouped and ordered.
// NOTE: tags are handled case insesitive.
// IMPORTANT: the order of appearance will be used by OW to classify your tags
tag = "DVR";
};
src/modules/writeTransferFunction/resources/WMWriteTransferFunction.png
0 → 100644
View file @
7679c99c
152 Bytes
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