Commit 0eb5212d authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[MERGE]

parents a1a5b210 9a36ffcd
......@@ -69,7 +69,7 @@ public:
typedef boost::shared_ptr< std::vector< size_t > > IndexArray;
/**
* Lengths of fibers in terms of verties.
* Lengths of fibers in terms of vertices.
*/
typedef boost::shared_ptr< std::vector< size_t > > LengthArray;
......
......@@ -3,6 +3,7 @@ ADD_MODULE( fiberTranslator )
ADD_MODULE( readAmiraMesh )
ADD_MODULE( readMesh )
ADD_MODULE( readRawData )
ADD_MODULE( writeAmiraMesh )
ADD_MODULE( writeDendrogram )
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 "core/kernel/WKernel.h"
#include "core/common/datastructures/WFiber.h"
#include "WMWriteAmiraMesh.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( WMWriteAmiraMesh )
WMWriteAmiraMesh::WMWriteAmiraMesh():
WModule()
{
}
WMWriteAmiraMesh::~WMWriteAmiraMesh()
{
// Cleanup!
}
boost::shared_ptr< WModule > WMWriteAmiraMesh::factory() const
{
// See "src/modules/template/" for an extensively documented example.
return boost::shared_ptr< WModule >( new WMWriteAmiraMesh() );
}
const std::string WMWriteAmiraMesh::getName() const
{
return "Write Amira Mesh";
}
const std::string WMWriteAmiraMesh::getDescription() const
{
return "Write AmiraMesh file format. At the moment only line sets are supported.";
}
void WMWriteAmiraMesh::connectors()
{
// Put the code for your connectors here. See "src/modules/template/" for an extensively documented example.
m_tractConnector = WModuleInputData< const WDataSetFibers >::createAndAdd( shared_from_this(), "tractInput", "A dataset of tracts" );
WModule::connectors();
}
void WMWriteAmiraMesh::properties()
{
// Put the code for your properties here. See "src/modules/template/" for an extensively documented example.
m_savePath = m_properties->addProperty( "Save Path", "Where to save the result", boost::filesystem::path( "/no/such/file" ) );
WPropertyHelper::PC_NOTEMPTY::addTo( m_savePath );
m_run = m_properties->addProperty( "Save", "Start saving", WPVBaseTypes::PV_TRIGGER_READY );
WModule::properties();
}
void WMWriteAmiraMesh::requirements()
{
}
void WMWriteAmiraMesh::moduleMain()
{
m_moduleState.add( m_tractConnector->getDataChangedCondition() );
m_moduleState.add( m_run->getCondition() );
ready();
while( !m_shutdownFlag() )
{
m_moduleState.wait();
if( !m_tractConnector->getData() )
{
continue;
}
if( m_run->get( true ) == WPVBaseTypes::PV_TRIGGER_TRIGGERED )
{
writeFile();
m_run->set( WPVBaseTypes::PV_TRIGGER_READY, true );
}
}
}
void WMWriteAmiraMesh::writeFile()
{
// open file
boost::filesystem::path meshFile( m_savePath->get() );
std::string fnPath = meshFile.string();
debugLog() << "Opening " << fnPath << " for writing.";
std::ofstream dataFile( fnPath.c_str(), std::ios_base::binary );
if( !dataFile )
{
errorLog() << "Opening " << fnPath << " failed.";
return;
}
// needed arrays for iterating the fibers
// WDataSetFibers::IndexArray fibStart = fibers->getLineStartIndexes();
WDataSetFibers::LengthArray fibLen = m_tractConnector->getData()->getLineLengths();
WDataSetFibers::VertexArray fibVerts = m_tractConnector->getData()->getVertices();
//WDataSetFibers::TangentArray fibTangents = fibers->getTangents();
std::size_t numPoints = fibVerts->size() / 3;
debugLog() << "Writing ...";
// write some head data
dataFile << "# AmiraMesh 3D ASCII 2.0" << std::endl << std::endl;
dataFile << "define Lines " << numPoints + m_tractConnector->getData()->size() << std::endl;
dataFile << "nVertices " << numPoints << std::endl;
dataFile << std::endl;
dataFile << "Parameters {" << std::endl;
dataFile << " ContentType \"HxLineSet\"" << std::endl;
dataFile << "}" << std::endl;
dataFile << std::endl;
dataFile << "Lines { int LineIdx } @1" << std::endl;
dataFile << "Vertices { float[3] Coordinates } @2" << std::endl;
dataFile << std::endl;
dataFile << "# Data section follows" << std::endl;
dataFile << std::endl;
dataFile << "@1" << std::endl;
size_t vertCounter = 0;
size_t lineId = 0;
for( size_t vertId = 0; vertId < numPoints; ++vertId )
{
dataFile << vertId << std::endl;
++vertCounter;
if( vertCounter == (*fibLen)[lineId] )
{
++lineId;
vertCounter = 0;
dataFile << -1 << std::endl;
}
}
dataFile << std::endl;
dataFile << "@2" << std::endl;
for( size_t vertId = 0; vertId < numPoints; ++vertId )
{
dataFile << (*fibVerts)[vertId*3+0] << " " << (*fibVerts)[vertId*3+1] << " " << (*fibVerts)[vertId*3+2] << " " << std::endl;
}
debugLog() << "Writing done.";
}
//---------------------------------------------------------------------------
//
// 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 WMWRITEAMIRAMESH_H
#define WMWRITEAMIRAMESH_H
#include <fstream>
#include <string>
#include <osg/Geode>
#include "core/dataHandler/WDataSetFibers.h"
#include "core/kernel/WModule.h"
#include "core/kernel/WModuleInputData.h"
#include "core/kernel/WModuleOutputData.h"
/**
* Someone should add some documentation here.
* Probably the best person would be the module's
* creator, i.e. "wiebel".
*
* This is only an empty template for a new module. For
* an example module containing many interesting concepts
* and extensive documentation have a look at "src/modules/template"
*
* \ingroup modules
*/
class WMWriteAmiraMesh: public WModule
{
public:
/**
*
*/
WMWriteAmiraMesh();
/**
*
*/
virtual ~WMWriteAmiraMesh();
/**
* 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();
/**
* Initialize requirements for this module.
*/
virtual void requirements();
private:
/**
* Writes the data to file.
*/
void writeFile();
WPropFilename m_savePath; //!< Path where tracts should be stored
/**
* Input connector for writing directly tracts to a file.
*/
boost::shared_ptr< WModuleInputData< const WDataSetFibers > > m_tractConnector;
WPropTrigger m_run; //!< Button to start saving
};
#endif // WMWRITEAMIRAMESH_H
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------
"Write Amira Mesh"
{
// Provide an icon. If the icon exists, it overrides the one provided by your
// getXPMIcon method. This path is relative to your module's resource directory.
icon="WMWriteAmiraMesh.xpm";
// Where to find the module?
website = "http://www.openwalnut.org";
// Provide a list of authors. These authors can have further information associated with them.
author = "OpenWalnut Project";
"OpenWalnut Project"
{
url="http://www.openwalnut.org";
email="contact@openwalnut.org";
what="Design, Development and Bug fixing";
};
tag = "IO";
};
/* XPM */
static const char * WMWriteAmiraMesh_xpm[] = {
"32 32 396 2",
" c None",
". c #262626",
"+ c #DCDCDC",
"@ c #FDFDFD",
"# c #AEAEAE",
"$ c #000000",
"% c #B0AFAF",
"& c #FDFDFC",
"* c #DCDCDB",
"= c #FDFDFE",
"- c #FEFDFD",
"; c #FDFCFD",
"> c #707070",
", c #8F8F8F",
"' c #F7F6F7",
") c #F7F7F7",
"! c #F7F7F6",
"~ c #676767",
"{ c #2A2A2A",
"] c #686868",
"^ c #F6F6F6",
"/ c #F7F6F6",
"( c #8D8D8D",
"_ c #6F6F6F",
": c #F6F6F7",
"< c #B5B5B5",
"[ c #444444",
"} c #EEEEEE",
"| c #EEEEED",
"1 c #232323",
"2 c #A8A8A8",
"3 c #EDEDEE",
"4 c #EEEDED",
"5 c #EDEDED",
"6 c #424343",
"7 c #B4B4B4",
"8 c #EEEDEE",
"9 c #EDEEEE",
"0 c #E3E3E3",
"a c #1A1A1A",
"b c #DDDDDC",
"c c #E6E6E6",
"d c #CACACA",
"e c #222222",
"f c #E5E5E6",
"g c #1D1D1D",
"h c #E6E5E6",
"i c #191919",
"j c #E2E2E2",
"k c #E5E5E5",
"l c #E6E6E5",
"m c #E5E6E6",
"n c #DEDEDE",
"o c #515151",
"p c #9C9C9C",
"q c #DEDDDD",
"r c #878787",
"s c #606060",
"t c #5C5C5C",
"u c #868686",
"v c #DEDEDD",
"w c #9B9B9B",
"x c #DDDDDD",
"y c #DEDDDE",
"z c #D6D6D6",
"A c #909090",
"B c #585857",
"C c #D6D6D5",
"D c #484748",
"E c #99999A",
"F c #D5D5D6",
"G c #969796",
"H c #464646",
"I c #D5D5D5",
"J c #565656",
"K c #D5D6D5",
"L c #D6D5D6",
"M c #CDCECD",
"N c #C4C4C3",
"O c #1E1E1E",
"P c #CBCACB",
"Q c #171717",
"R c #C6C6C6",
"S c #CDCDCD",
"T c #C4C5C5",
"U c #101010",
"V c #C4C4C4",
"W c #1D1D1C",
"X c #C3C3C3",
"Y c #CECECE",
"Z c #CECDCE",
"` c #CDCECE",
" . c #CECECD",
".. c #C6C5C6",
"+. c #373737",
"@. c #3C3C3C",
"#. c #393939",
"$. c #C5C5C5",
"%. c #363737",
"&. c #363636",
"*. c #C5C6C6",
"=. c #C5C5C6",
"-. c #BEBDBE",
";. c #6C6D6D",
">. c #BDBDBD",
",. c #BEBDBD",
"'. c #BDBEBD",
"). c #6A6A6A",
"!. c #BDBDBC",
"~. c #BDBCBC",
"{. c #BDBEBE",
"]. c #BDBDBE",
"^. c #B6B5B6",
"/. c #A2A2A1",
"(. c #9B9B9C",
"_. c #B5B5B6",
":. c #9A9A9A",
"<. c #A1A1A1",
"[. c #B5B4B5",
"}. c #B4B5B5",
"|. c #B4B5B4",
"1. c #B4B4B5",
"2. c #B6B6B5",
"3. c #B5B6B6",
"4. c #AEADAD",
"5. c #ADADAD",
"6. c #ADADAE",
"7. c #ADACAD",
"8. c #ACADAD",
"9. c #ADADAC",
"0. c #A5A5A6",
"a. c #A5A5A5",
"b. c #A5A6A5",
"c. c #A4A5A5",
"d. c #A5A4A5",
"e. c #A4A4A5",
"f. c #A4A5A4",
"g. c #9E9D9E",
"h. c #9E9D9D",
"i. c #9D9D9D",
"j. c #9D9C9D",
"k. c #9C9D9C",
"l. c #9C9D9D",
"m. c #959595",
"n. c #959695",
"o. c #949594",
"p. c #959594",
"q. c #949595",
"r. c #959494",
"s. c #949494",
"t. c #8D8D8C",
"u. c #8C8D8C",
"v. c #8D8C8C",
"w. c #8C8D8D",
"x. c #858585",
"y. c #858485",
"z. c #858484",
"A. c #848585",
"B. c #848584",
"C. c #848485",
"D. c #848484",
"E. c #7E7E7D",
"F. c #7E7E7E",
"G. c #7E7D7E",
"H. c #7D7E7D",
"I. c #7D7D7D",
"J. c #7D7D7E",
"K. c #7E7D7D",
"L. c #7C7D7D",
"M. c #7C7D7C",
"N. c #7C7C7C",
"O. c #7C7C7D",
"P. c #7D7C7C",
"Q. c #767576",
"R. c #767575",
"S. c #757676",
"T. c #767676",
"U. c #757575",
"V. c #757576",
"W. c #747575",
"X. c #747574",
"Y. c #757475",
"Z. c #757574",
"`. c #747474",
" + c #747475",
".+ c #757474",
"++ c #6E6E6E",
"@+ c #6E6D6E",
"#+ c #6D6D6D",
"$+ c #6D6E6D",
"%+ c #6D6E6E",
"&+ c #6E6D6D",
"*+ c #6D6D6E",
"=+ c #6D6D6C",
"-+ c #6C6C6D",
";+ c #6D6C6C",
">+ c #6C6C6C",
",+ c #6C6D6C",
"'+ c #666665",
")+ c #666565",
"!+ c #656665",
"~+ c #656565",
"{+ c #656566",
"]+ c #646565",
"^+ c #656465",
"/+ c #646564",
"(+ c #646465",
"_+ c #656464",
":+ c #646464",
"<+ c #5E5E5D",
"[+ c #5D5E5D",
"}+ c #5D5D5D",
"|+ c #5E5D5D",
"1+ c #5C5D5D",
"2+ c #5D5D5C",
"3+ c #5D5C5C",
"4+ c #565655",
"5+ c #555655",
"6+ c #555556",
"7+ c #555555",
"8+ c #545554",
"9+ c #555455",
"0+ c #555554",
"a+ c #545555",
"b+ c #555454",
"c+ c #545454",
"d+ c #545455",
"e+ c #4D4E4E",
"f+ c #4D4E4D",
"g+ c #4D4D4E",
"h+ c #4D4D4D",
"i+ c #4D4C4D",
"j+ c #4C4D4D",
"k+ c #4D4D4C",
"l+ c #565F4F",
"m+ c #4C4D4C",
"n+ c #4C4C4D",
"o+ c #4C4C4C",
"p+ c #454546",
"q+ c #454545",
"r+ c #444545",
"s+ c #454445",
"t+ c #444445",
"u+ c #454444",
"v+ c #85B759",
"w+ c #3D3D3E",
"x+ c #3D3D3D",
"y+ c #40423E",
"z+ c #536245",
"A+ c #4B5542",
"B+ c #41453F",
"C+ c #4F5D44",
"D+ c #4B5642",
"E+ c #42463F",
"F+ c #526245",
"G+ c #3E403D",
"H+ c #3C3C3D",
"I+ c #3D3C3D",
"J+ c #43473F",
"K+ c #3D3C3C",
"L+ c #3D3D3C",
"M+ c #40433D",
"N+ c #536445",
"O+ c #464D40",