Commit 832d9643 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[REMOVE] - removed LIC module. It was not complying our style/doc guidelines,...

[REMOVE] - removed LIC module. It was not complying our style/doc guidelines, it was slow, modified data illegally, and the worst: it contained source which is NOT opensource (numerical recipies). You can revive the module if you remove the fibernavigator/fantom code AND use eigen3 for those copyright-critical parts.
parent 52b273b5
//---------------------------------------------------------------------------
//
// 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 <vector>
#include <osg/LightModel>
#include "core/common/WSharedSequenceContainer.h"
#include "core/dataHandler/exceptions/WDHNoSuchSubject.h"
#include "core/dataHandler/WDataHandler.h"
#include "core/dataHandler/WDataSetVector.h"
#include "core/dataHandler/WSubject.h"
#include "core/graphicsEngine/shaders/WGEShader.h"
#include "core/graphicsEngine/WGEUtils.h"
#include "core/graphicsEngine/WTriangleMesh.h"
#include "core/kernel/WKernel.h"
#include "fibernavigator/SurfaceLIC.h"
#include "WMLIC.h"
#include "WMLIC.xpm"
// This line is needed by the module loader to actually find your module.
W_LOADABLE_MODULE( WMLIC )
WMLIC::WMLIC()
: WModule(),
m_moduleNode( new WGEGroupNode() ),
m_surfaceGeode( 0 )
{
}
WMLIC::~WMLIC()
{
// Cleanup!
}
boost::shared_ptr< WModule > WMLIC::factory() const
{
return boost::shared_ptr< WModule >( new WMLIC() );
}
const char** WMLIC::getXPMIcon() const
{
return lic_xpm;
}
const std::string WMLIC::getName() const
{
return "LIC";
}
const std::string WMLIC::getDescription() const
{
return "Line integrate convolution on TriangleMesh with a WDataSetVector";
}
void WMLIC::connectors()
{
m_meshIC = boost::shared_ptr< WModuleInputData < WTriangleMesh > >(
new WModuleInputData< WTriangleMesh >( shared_from_this(),
"inMesh", "The triangle mesh used for painting the LIC" )
);
// TODO(math): reenable the connector when selecting of two input in GUI is possible.
// The reason for disabling is just that you can choose the lic on a surface without project files due to its two inputs
// Alternatively the vector dataset is choosen from first subject dataset containing evec in its file name, see moduleMain
// for more informations.
//
// m_vectorIC = boost::shared_ptr< WModuleInputData < WDataSetVector > >(
// new WModuleInputData< WDataSetVector >( shared_from_this(),
// "inVectorDS", "The vectors used for computing the Streamlines used for the LIC" )
// );
// TODO(math): ATM we are unsure about providing an output. Caution the input mesh is modified!
// m_meshOC = boost::shared_ptr< WModuleOutputData < WTriangleMesh > >(
// new WModuleOutputData< WTriangleMesh >( shared_from_this(),
// "outMesh", "The LIC" )
// );
addConnector( m_meshIC );
// addConnector( m_vectorIC );
// addConnector( m_meshOC );
WModule::connectors();
}
void WMLIC::properties()
{
WModule::properties();
}
void WMLIC::renderMesh( boost::shared_ptr< WTriangleMesh > mesh )
{
m_moduleNode->remove( m_surfaceGeode );
osg::Geometry* surfaceGeometry = new osg::Geometry();
m_surfaceGeode = osg::ref_ptr< osg::Geode >( new osg::Geode );
surfaceGeometry->setVertexArray( mesh->getVertexArray() );
osg::DrawElementsUInt* surfaceElement;
surfaceElement = new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );
std::vector< size_t > tris = mesh->getTriangles();
surfaceElement->reserve( tris.size() );
for( unsigned int vertId = 0; vertId < tris.size(); ++vertId )
{
surfaceElement->push_back( tris[vertId] );
}
surfaceGeometry->addPrimitiveSet( surfaceElement );
// ------------------------------------------------
// normals
surfaceGeometry->setNormalArray( mesh->getVertexNormalArray() );
surfaceGeometry->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
m_surfaceGeode->addDrawable( surfaceGeometry );
osg::StateSet* state = m_surfaceGeode->getOrCreateStateSet();
// ------------------------------------------------
// colors
surfaceGeometry->setColorArray( mesh->getTriangleColors() );
surfaceGeometry->setColorBinding( osg::Geometry::BIND_PER_PRIMITIVE );
osg::ref_ptr<osg::LightModel> lightModel = new osg::LightModel();
lightModel->setTwoSided( true );
state->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
state->setMode( GL_BLEND, osg::StateAttribute::ON );
{
osg::ref_ptr< osg::Material > material = new osg::Material();
material->setDiffuse( osg::Material::FRONT, osg::Vec4( 1.0, 1.0, 1.0, 1.0 ) );
material->setSpecular( osg::Material::FRONT, osg::Vec4( 0.0, 0.0, 0.0, 1.0 ) );
material->setAmbient( osg::Material::FRONT, osg::Vec4( 0.1, 0.1, 0.1, 1.0 ) );
material->setEmission( osg::Material::FRONT, osg::Vec4( 0.0, 0.0, 0.0, 1.0 ) );
material->setShininess( osg::Material::FRONT, 25.0 );
state->setAttribute( material );
}
m_moduleNode->insert( m_surfaceGeode );
m_shader = osg::ref_ptr< WGEShader > ( new WGEShader( "WMLIC", m_localPath ) );
m_shader->apply( m_surfaceGeode );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_moduleNode );
}
void WMLIC::moduleMain()
{
m_moduleState.setResetable( true, true );
m_moduleState.add( m_meshIC->getDataChangedCondition() );
// m_moduleState.add( m_vectorIC->getDataChangedCondition() );
ready();
while( !m_shutdownFlag() )
{
m_moduleState.wait();
if( m_shutdownFlag() )
{
break;
}
boost::shared_ptr< WTriangleMesh > newMesh = m_meshIC->getData();
// TODO(math): if the vector input is available again please enable this again too
// boost::shared_ptr< WDataSetVector > newVector = m_vectorIC->getData();
// bool dataChanged = ( m_inMesh != newMesh ) || ( m_inVector != newVector );
// bool dataValid = ( newMesh.get() && newVector.get() );
bool dataChanged = ( m_inMesh != newMesh );
bool dataValid = newMesh.get();
if( dataChanged && dataValid )
{
boost::shared_ptr< WProgress > progress = boost::shared_ptr< WProgress >( new WProgress( "LIC", 5 ) );
m_progress->addSubProgress( progress );
debugLog() << "Received Data.";
m_inMesh = newMesh;
// m_inVector = newVector;
WAssert( m_inVector = searchVectorDS(), "There was no vector dataset loaded, please load it first!" );
++*progress;
m_inMesh->doLoopSubD();
++*progress;
m_inMesh->doLoopSubD();
++*progress;
SurfaceLIC lic( m_inVector, m_inMesh );
lic.execute();
lic.updateMeshColor( m_inMesh );
// m_meshOC.updateData( m_inMesh );
debugLog() << "Start rendering LIC";
renderMesh( m_inMesh );
debugLog() << "Rendering done";
++*progress;
progress->finish();
}
}
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_moduleNode );
}
boost::shared_ptr< WDataSetVector > WMLIC::searchVectorDS() const
{
boost::shared_ptr< WDataSetVector > result;
boost::shared_ptr< WSubject > subject;
try
{
subject = WDataHandler::getDefaultSubject();
}
catch( WDHNoSuchSubject )
{
return result;
}
if( !subject )
{
return result;
}
// This lock gets unlocked if it is destroyed ( looses scope )
WSubject::DatasetSharedContainerType::ReadTicket da = subject->getDatasets();
for( WSubject::DatasetConstIterator it = da->get().begin(); it != da->get().end(); ++it )
{
if( ( *it )->isVectorDataSet() )
{
return ( *it )->isVectorDataSet();
}
}
return result;
}
void WMLIC::activate()
{
if( m_moduleNode )
{
if( m_active->get() )
{
m_moduleNode->setNodeMask( 0xFFFFFFFF );
}
else
{
m_moduleNode->setNodeMask( 0x0 );
}
}
WModule::activate();
}
//---------------------------------------------------------------------------
//
// 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 WMLIC_H
#define WMLIC_H
#include <string>
#include <osg/Geode>
#include "core/kernel/WModule.h"
#include "core/kernel/WModuleInputData.h"
#include "core/kernel/WModuleOutputData.h"
// forward declarations
class WGEShader;
class WDataSetVector;
class WTriangleMesh;
/**
* Computes a Line Intregrated Convolution from a vector field onto a triangle mesh.
* \warning Most of the code is taken from fantom and the fibernavigator. DO NOT scatter those sources in OpenWalnut!
* \ingroup modules
*/
class WMLIC: public WModule
{
public:
/**
* Constructs a new LIC module
*/
WMLIC();
/**
* Destructs and clean up this module
*/
virtual ~WMLIC();
/**
* 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.
*/
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();
/**
* Generates an OSG geode for the mesh
*
* \param mesh the mesh which represents the LIC
*/
void renderMesh( boost::shared_ptr< WTriangleMesh > mesh );
void activate();
private:
/**
* Searches for the first dataset in subject 0 containing the phrase "evec" in its filename and check if its a vector dataset.
*
* \return reference to the vector dataset
*/
boost::shared_ptr< WDataSetVector > searchVectorDS() const;
boost::shared_ptr< WModuleInputData< WTriangleMesh > > m_meshIC; //!< The InputConnector for the mesh on which to paint
// boost::shared_ptr< WModuleInputData< WDataSetVector > > m_vectorIC; //!< The InputConnector for the vectors that are used to build the streamlines
boost::shared_ptr< WTriangleMesh > m_inMesh; //!< The mesh given from the input connector
boost::shared_ptr< WDataSetVector > m_inVector; //!< The vector field used to compute the LIC given from the input connector
// boost::shared_ptr< WModuleOutputData< WTriangleMesh > > m_meshOC; //!< OutputConnector for the LIC'ed mesh
osg::ref_ptr< WGEGroupNode > m_moduleNode; //!< Pointer to the modules group node.
osg::ref_ptr< osg::Geode > m_surfaceGeode; //!< Pointer to geode containing the surface.
osg::ref_ptr< WGEShader > m_shader; //!< The shader used for the iso surface in m_geode
};
#endif // WMLIC_H
/* XPM */
static const char * lic_xpm[] = {
"32 32 35 1",
" c None",
". c #A7A7A7",
"+ c #D5D5D5",
"@ c #AAAAAA",
"# c #BDBDBD",
"$ c #CCCCCC",
"% c #D3D3D3",
"& c #CBCBCB",
"* c #BABABA",
"= c #AFAFAF",
"- c #D0D0D0",
"; c #C9C9C9",
"> c #A8A8A8",
", c #A9A9A9",
"' c #CFCFCF",
") c #C8C8C8",
"! c #B1B1B1",
"~ c #B9B9B9",
"{ c #BEBEBE",
"] c #BCBCBC",
"^ c #CACACA",
"/ c #B8B8B8",
"( c #B5B5B5",
"_ c #B2B2B2",
": c #D2D2D2",
"< c #D4D4D4",
"[ c #D1D1D1",
"} c #ABABAB",
"| c #B3B3B3",
"1 c #BBBBBB",
"2 c #B4B4B4",
"3 c #C7C7C7",
"4 c #B0B0B0",
"5 c #C3C3C3",
"6 c #C6C6C6",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"....++........++....@#$%%&*.....",
"....++........++...=-++++++;>...",
"....++........++..,'+)!>,~%+{...",
"....++........++..]+^...../+'...",
"....++........++..&+(......_@...",
"....++........++..:+@...........",
"....++........++..<+............",
"....++........++..[+}...........",
"....++........++..;+(......>|...",
"....++........++..1+;.....2%3...",
"....++........++..,-+3=.@/%+|...",
"....++++++++..++...4'++++++5....",
"....++++++++..++....>/6[%&*.....",
"................................",
"................................"};
//---------------------------------------------------------------------------
//
// Project: FAnToM
// Module: $RCSfile: FArray.cc,v $
// Language: C++
// Date: $Date: 2003/07/02 08:07:12 $
// Author: $Author: garth $
// Version: $Revision: 1.23 $
//
//---------------------------------------------------------------------------
#include <ctype.h>
#include <iomanip>
using namespace std;
#include "FArray.h"
#include "FString.h"
#include "FException.h"
#include "FMatrix.h"
#include "binio.h"
#ifdef OUTLINE
#include "FArray.icc"
#endif
//--------------------------------------------------------------------
FArray::FArray()
{
// for test purpose...
// consistent with the default constructor of the former FVector class
// comp=new double[3]; sizeOfArray=3;
// memset(comp, 0, 3*sizeof(double));
comp = 0;
sizeOfArray = 0;
}
//---------------------------------------------------------------------
FArray::FArray(unsigned int s)
{
comp=new double[s];
sizeOfArray=s;
memset(comp, 0, s*sizeof(double));
}
//---------------------------------------------------------------------
FArray::FArray(const FArray& a)
{
sizeOfArray=a.sizeOfArray;
comp=new double[sizeOfArray];
memcpy(comp, a.comp, sizeOfArray*sizeof(double));
}
//---------------------------------------------------------------------
FArray::FArray(const std::vector<double>& a)
{
sizeOfArray=a.size();
comp=new double[sizeOfArray];
// copy the elements
unsigned int j;
for(j=0;j<sizeOfArray; j++)
comp[j]=a[j];
}
//---------------------------------------------------------------------
FArray::FArray(unsigned int s, const double ref[])
{
comp= new double[s];
sizeOfArray = s;
memcpy(comp, ref, s*sizeof(double));
}
//---------------------------------------------------------------------
FArray::FArray(double x, double y, double z, double w, double w2, double w3)
{
sizeOfArray=6;
comp=new double[6];
comp[0] = x;
comp[1] = y;
comp[2] = z;
comp[3] = w;
comp[4] = w2;
comp[5] = w3;
}
//---------------------------------------------------------------------
FArray::FArray(double x, double y, double z, double w, double w2)
{
sizeOfArray=5;
comp=new double[5];
comp[0] = x;
comp[1] = y;
comp[2] = z;
comp[3] = w;
comp[4] = w2;
}
//---------------------------------------------------------------------
FArray::FArray(double x, double y, double z, double w)
{
sizeOfArray=4;
comp=new double[4];
comp[0] = x;
comp[1] = y;
comp[2] = z;
comp[3] = w;
}
//---------------------------------------------------------------------
FArray::FArray(double x, double y, double z)
{
sizeOfArray=3;
comp=new double[3];
comp[0] = x;
comp[1] = y;
comp[2] = z;
}
//---------------------------------------------------------------------------
FArray::FArray(double x, double y)
{
sizeOfArray=2;
comp=new double[2];
comp[0] = x;
comp[1] = y;
}
//---------------------------------------------------------------------------
FArray::FArray(const FMatrix& m)
{
sizeOfArray=m.getDimensionX()*m.getDimensionY();
comp=new double[sizeOfArray];
for(unsigned int s=0; s<sizeOfArray; s++)
comp[s] = m[s];
}
//---------------------------------------------------------------------
FArray::FArray(unsigned int /*c*/, double /*v*/)
{
THROW_EXCEPTION(FException, "Ambigous! Please take a look at FArray.hh!");
}
//---------------------------------------------------------------------
FArray::~FArray()
{
if(comp) delete[] comp;
}
//---------------------------------------------------------------------------
void FArray::resize(unsigned int s, bool keepContent)
{