Commit fa498b7c authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[CHANGE] moved module from main repo to module repo

parent a52068b7
......@@ -3,6 +3,5 @@ ADD_MODULE( fiberTranslator )
ADD_MODULE( readMesh )
ADD_MODULE( readRawData )
ADD_MODULE( writeDendrogram )
ADD_MODULE( writeGeometry )
ADD_MODULE( writeMesh )
ADD_MODULE( writeTracts )
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------
#include <string>
#include <sstream>
#include <fstream>
#include "core/common/WPropertyHelper.h"
#include "core/graphicsEngine/WTriangleMesh.h"
#include "core/kernel/WKernel.h"
#include "WMWriteGeometry.xpm"
#include "WMWriteGeometry.h"
// This line is needed by the module loader to actually find your module. Do not remove. Do NOT add a ";" here.
W_LOADABLE_MODULE( WMWriteGeometry )
WMWriteGeometry::WMWriteGeometry():
WModule()
{
}
WMWriteGeometry::~WMWriteGeometry()
{
// Cleanup!
}
boost::shared_ptr< WModule > WMWriteGeometry::factory() const
{
// See "src/modules/template/" for an extensively documented example.
return boost::shared_ptr< WModule >( new WMWriteGeometry() );
}
const char** WMWriteGeometry::getXPMIcon() const
{
return WMWriteGeometry_xpm;
}
const std::string WMWriteGeometry::getName() const
{
// Specify your module name here. This name must be UNIQUE!
return "Write Geometry";
}
const std::string WMWriteGeometry::getDescription() const
{
// Specify your module description here. Be detailed. This text is read by the user.
// See "src/modules/template/" for an extensively documented example.
return "Exports triangle meshes to certain file formats. VRML implemented so far.";
}
void WMWriteGeometry::connectors()
{
m_input = boost::shared_ptr< WModuleInputData < WTriangleMesh > >(
new WModuleInputData< WTriangleMesh >( shared_from_this(), "Triangle Mesh", "The mesh that will be stored." )
);
addConnector( m_input );
// call WModules initialization
WModule::connectors();
}
void WMWriteGeometry::properties()
{
m_savePath = m_properties->addProperty( "Save Path", "Where to save the result", boost::filesystem::path( "/tmp/test.wrl" ) );
WPropertyHelper::PC_NOTEMPTY::addTo( m_savePath );
WModule::properties();
}
void WMWriteGeometry::moduleMain()
{
m_moduleState.add( m_input->getDataChangedCondition() );
// signal ready state
ready();
// loop until the module container requests the module to quit
while( !m_shutdownFlag() )
{
if( !m_input->getData() )
{
// ok, the output has not yet sent data
// NOTE: see comment at the end of this while loop for m_moduleState
debugLog() << "Waiting for data ...";
m_moduleState.wait();
continue;
}
writeFile();
// this waits for m_moduleState to fire. By default, this is only the m_shutdownFlag condition.
// NOTE: you can add your own conditions to m_moduleState using m_moduleState.add( ... )
m_moduleState.wait();
}
}
void WMWriteGeometry::writeFile()
{
boost::shared_ptr< WTriangleMesh > mesh = m_input->getData();
using std::fstream;
fstream out( m_savePath->get().string().c_str(), fstream::out | fstream::in | fstream::trunc | fstream::binary );
if( !out || out.bad() )
{
throw WException( std::string( "Invalid file, or permission: " ) + m_savePath->get().string() );
}
std::string appearance = ""
"appearance Appearance {\n"
"material Material {\n"
"diffuseColor 0.0 1.0 1.0\n"
"}\n"
"}\n";
std::stringstream points;
for( size_t i = 0; i < mesh->vertSize(); ++i )
{
WPosition pos = mesh->getVertex( i );
points << "" << pos[0] << " " << pos[1] << " " << pos[2];
if( i < mesh->vertSize() - 1 )
{
points << ",\n ";
}
}
std::stringstream indices;
for( size_t i = 0; i < mesh->triangleSize(); ++i )
{
indices << "" << mesh->getTriVertId0( i ) << ", ";
indices << "" << mesh->getTriVertId1( i ) << ", ";
indices << "" << mesh->getTriVertId2( i );
if( i < mesh->triangleSize() - 1 )
{
indices << ", -1,\n ";
}
}
out << "#VRML V2.0 utf8" << std::endl;
out << "# Written with OpenWalnut ( http://www.openwalnut.org )." << std::endl;
out << "Shape {" << std::endl;
out << appearance << std::endl;
out << "geometry IndexedFaceSet {" << std::endl;
out << "coord DEF SurfaceCoords Coordinate {" << std::endl;
out << "point [" << std::endl;
out << points.str() << std::endl;
out << "]" << std::endl;
out << "}" << std::endl;
out << "coordIndex [" << std::endl;
out << indices.str() << std::endl;
out << "]" << std::endl;
out << "}" << std::endl;
out << "}" << std::endl;
out.close();
debugLog() << "Data written to file.";
}
//---------------------------------------------------------------------------
//
// 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 WMWRITEGEOMETRY_H
#define WMWRITEGEOMETRY_H
#include <string>
#include <osg/Geode>
#include "core/kernel/WModule.h"
#include "core/kernel/WModuleInputData.h"
#include "core/kernel/WModuleOutputData.h"
class WTriangleMesh;
/**
* This module writes out geomtry, e.g. surfaces to various
* geomtry file formats. At the moment only VRML.
*
* \ingroup modules
*/
class WMWriteGeometry: public WModule
{
public:
/**
*
*/
WMWriteGeometry();
/**
*
*/
virtual ~WMWriteGeometry();
/**
* 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;
/**
* Get the icon for this module in XPM format.
* \return The icon.
*/
virtual const char** getXPMIcon() 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:
/**
* Routine that acutally writes the file.
*/
void writeFile();
/**
* An input connector used to get mehses from other modules.
*/
boost::shared_ptr< WModuleInputData< WTriangleMesh > > m_input;
WPropFilename m_savePath; //!< Path where geometry should be stored
};
#endif // WMWRITEGEOMETRY_H
/* XPM */
static const char * WMWriteGeometry_xpm[] = {
"32 32 128 2",
" c None",
". c #000000",
"+ c #FFFFFF",
"@ c #FEFDFE",
"# c #FDFBFD",
"$ c #FDF9FC",
"% c #FCF6FC",
"& c #FBF5FA",
"* c #FAF2F9",
"= c #CDCDCD",
"- c #CECECE",
"; c #FEFBFD",
"> c #FDF9FD",
", c #FAF3FA",
"' c #F8F8F8",
") c #F9F9F9",
"! c #D1D1D1",
"~ c #FFFDFF",
"{ c #FBF7FB",
"] c #FBF4FB",
"^ c #FBF3FA",
"/ c #F9F0F9",
"( c #F9EFF8",
"_ c #F8ECF7",
": c #F7EAF6",
"< c #F6E8F6",
"[ c #F6E6F4",
"} c #F5E3F3",
"| c #F4E1F3",
"1 c #F3E0F2",
"2 c #F2DDF1",
"3 c #F2DBF0",
"4 c #F0D9EF",
"5 c #F0D7EE",
"6 c #EFD5ED",
"7 c #EED3ED",
"8 c #EED1EC",
"9 c #D2D2D2",
"0 c #FCF8FD",
"a c #F5E3F4",
"b c #F4E1F2",
"c c #F3DFF1",
"d c #F2DBF1",
"e c #EFD7EE",
"f c #EFD5EE",
"g c #FEFEFE",
"h c #F3DFF2",
"i c #F1DBF0",
"j c #F0D8EF",
"k c #EED2ED",
"l c #EDD1EB",
"m c #FEFDFF",
"n c #FAF2FA",
"o c #FAF0F9",
"p c #F8EEF8",
"q c #F7ECF7",
"r c #F7EAF7",
"s c #F6E8F5",
"t c #F3E1F3",
"u c #F1D9EF",
"v c #F0D6EF",
"w c #EFD3EC",
"x c #EDD0EB",
"y c #636363",
"z c #FFFDFE",
"A c #FAF1F9",
"B c #F6E6F5",
"C c #F4E3F4",
"D c #F0D6EE",
"E c #EED2EC",
"F c #EED0EC",
"G c #D9D9D9",
"H c #646464",
"I c #FCF7FB",
"J c #F9F0F8",
"K c #F7E9F6",
"L c #F7E8F5",
"M c #F5E5F4",
"N c #F4E4F3",
"O c #F4E2F3",
"P c #616161",
"Q c #6B6B6B",
"R c #9A9A9A",
"S c #8B8B8B",
"T c #6C6C6C",
"U c #FCF6FB",
"V c #5A5A5A",
"W c #5C5C5C",
"X c #626262",
"Y c #FBF5FB",
"Z c #F3DDF1",
"` c #5D5D5D",
" . c #5E5E5E",
".. c #FDF8FC",
"+. c #686868",
"@. c #858585",
"#. c #7C7C7C",
"$. c #F1D8EF",
"%. c #F0D7EF",
"&. c #EFD4ED",
"*. c #EED0EB",
"=. c #D7D7D7",
"-. c #F8EEF7",
";. c #F4E2F2",
">. c #EFD7EF",
",. c #EFD4EE",
"'. c #F9EEF8",
"). c #F3E2F3",
"!. c #EFD6EE",
"~. c #EED3EC",
"{. c #EED4ED",
"]. c #FEFCFE",
"^. c #EFD6EF",
"/. c #EDD0EC",
"(. c #FEFBFE",
"_. c #F6E7F5",
":. c #F5E6F4",
"<. c #F4E3F3",
"[. c #F5E5F5",
"}. c #FDFAFD",
"|. c #FDF8FD",
"1. c #F8EBF7",
"2. c #F1DAF0",
"3. c #FFFFFE",
"4. c #FDFAFE",
"5. c #FCF9FC",
"6. c #FCF7FC",
"7. c #FBF4FA",
". . . . . . . ",
". . . . . . . ",
". . . . . . . ",
" . . . . . . . ",
" . . . . . . . . ",
" . . . . . . . . ",
" . . . . . . . . ",
" . . . . . . ",
" . . . . . . ",
" . . . . . . ",
" ",
"+ @ # $ % & * = = = = = = = = = = = = = = = = = - ",
"+ @ ; > % & , ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ) ' ! ",
"+ ~ # > { ] ^ / ( _ : < [ } | 1 2 3 4 5 6 7 8 + 9 ",
"+ @ # 0 % . . . . . . . . a b c 2 d 4 e f 7 8 g 9 ",
"+ @ # . . . . . . . . . . . | h 2 i j 5 6 k l g 9 ",
"+ m . . . . n o p q r s . . t 1 2 i u v f w x g 9 y y ",
"+ z . . . ] n A p _ : < B C t h 2 3 u D 6 E F + G H H y ",
"+ . . . I ] , J p _ K L M N O h 2 H H H H P Q R S T P H y H H ",
"+ . . . U ] n o . . . . . . | h 2 3 H H H H y V W X H H H H y H ",
"+ . . 0 % Y n / . . . . . . O h Z 3 H H H H y ` .y H H H H H H ",
"+ . . ..U Y , J p . : . . . | c 2 y H H y X +.@.#.+.X H H H H ",
"+ . . . U Y n J p _ : . . . O h 2 i $.%.&.E *.+ =. H H y ",
"+ . . . I & n o -.q : . . . ;.c Z i u >.,.k x g 9 H H ",
"+ @ . . . ] n o '._ : . . . ).h 2 i $.!.&.~.x g 9 ",
"+ @ . . . . n / -._ K . . . b h 2 i j %.{.~.x g 9 ",
"+ ].# . . . . . . . . . . a | c 2 i u ^.&.E /.g 9 ",
"+ @ (.0 % . . . . . . _.:.<.| c 2 3 u 5 ,.~.x g 9 ",
"+ ].# $ I & n J p _ : _.[.C ;.h 2 i u D ,.~.x g 9 ",
"+ @ }.|.U & * / p 1.: _.:.} b h 2 2.4 D &.7 /.+ 9 ",
"3.@ 4.5.U Y n ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ) ' ! ",
"+ @ # 0 6.7.n = = = = = = = = = = = = = = = = = - "};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment