*** empty log message ***
This commit is contained in:
parent
e9b8ee44e1
commit
34cce21f3a
|
@ -1,168 +0,0 @@
|
|||
#ifndef COLLISION_DETECTION
|
||||
#define COLLISION_DETECTION
|
||||
|
||||
#include <set>
|
||||
#include <vcg/space/index/spatial_hashing.h>
|
||||
#include <vcg/space/intersection3.h>
|
||||
|
||||
template <class ContSimplex>
|
||||
class Collision_Detector{
|
||||
|
||||
public:
|
||||
|
||||
typedef typename ContSimplex::value_type SimplexType;
|
||||
typedef typename ContSimplex::value_type* SimplexPointer;
|
||||
typedef typename ContSimplex::iterator SimplexIterator;
|
||||
typedef typename SimplexType::CoordType CoordType;
|
||||
typedef typename CoordType::ScalarType ScalarType;
|
||||
typedef typename vcg::Box3<ScalarType> Box3x;
|
||||
|
||||
typedef DynamicSpatialHashTable<SimplexType,float> HashingTable;
|
||||
|
||||
Collision_Detector(ContSimplex & r_):_simplex(r_){};
|
||||
~Collision_Detector(){};
|
||||
|
||||
ContSimplex & _simplex;
|
||||
|
||||
HashingTable *HTable;
|
||||
|
||||
std::set<Point3i> vactive;
|
||||
|
||||
int active;
|
||||
|
||||
//control if two faces share an edge
|
||||
bool ShareEdge(SimplexType *f0,SimplexType *f1)
|
||||
{
|
||||
assert((!f0->IsD())&&(!f1->IsD()));
|
||||
for (int i=0;i<3;i++)
|
||||
if (f0->FFp(i)==f1)
|
||||
return (true);
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
///initialize the box for collision detection and the dimension of a cell
|
||||
void Init(CoordType _min,CoordType _max,ScalarType _l)
|
||||
{
|
||||
HTable=new HashingTable();
|
||||
Box3x bb(_min,_max);
|
||||
CoordType d=((_max-_min)/_l);
|
||||
vcg::Point3i dim;
|
||||
dim.Import<ScalarType>(d);
|
||||
HTable->InitEmpty(bb,dim);
|
||||
}
|
||||
|
||||
//control if two faces share a vertex
|
||||
bool ShareVertex(SimplexType *f0,SimplexType *f1)
|
||||
{
|
||||
assert((!f0->IsD())&&(!f1->IsD()));
|
||||
for (int i=0;i<3;i++)
|
||||
for (int j=0;j<3;j++)
|
||||
if (f0->V(i)==f1->V(j))
|
||||
return (true);
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
//test real intersection between faces
|
||||
bool TestRealIntersection(SimplexType *f0,SimplexType *f1)
|
||||
{
|
||||
assert((!f0->IsD())&&(!f1->IsD()));
|
||||
if ((!f0->IsActive())&&(!f1->IsActive()))
|
||||
return false;
|
||||
//no adiacent faces
|
||||
assert(f0!=f1);
|
||||
if ((f0!=f1)&& (!ShareEdge(f0,f1))&&!ShareVertex(f0,f1))
|
||||
{
|
||||
//vcg::Segment3<ScalarType> segm;
|
||||
//bool copl=false;
|
||||
return (vcg::Intersection<SimplexType>((*f0),(*f1)));//,copl,segm))
|
||||
//return ((copl)||(segm.Length()>0.001));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
///refresh all the elements of spatial hashing table
|
||||
void RefreshElements()
|
||||
{
|
||||
HTable->Clear();
|
||||
vactive.clear();
|
||||
|
||||
HTable->tempMark=0;
|
||||
|
||||
for (SimplexIterator si=_simplex.begin();si<_simplex.end();++si)
|
||||
{
|
||||
if (!(*si).IsD())
|
||||
{
|
||||
(*si).HMark()=0;
|
||||
vcg::Box3i cells=HTable->Add(&*si);
|
||||
if ((*si).IsActive())
|
||||
{
|
||||
vcg::Box3i cells=HTable->Add(&*si);
|
||||
for (int x=cells.min.X(); x<=cells.max.X();x++)
|
||||
for (int y=cells.min.Y(); y<=cells.max.Y();y++)
|
||||
for (int z=cells.min.Z(); z<=cells.max.Z();z++)
|
||||
vactive.insert(vcg::Point3i(x,y,z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///put active cells on apposite structure
|
||||
template <class Container_Type>
|
||||
void UpdateStep(Container_Type &simplex)
|
||||
{
|
||||
vactive.clear();
|
||||
HTable->UpdateTmark();
|
||||
for (Container_Type::iterator si=simplex.begin();si<simplex.end();++si)
|
||||
{
|
||||
if ((!(*si).IsD())&&((*si).IsActive()))
|
||||
{
|
||||
vcg::Box3i cells=HTable->Add(&*si);
|
||||
for (int x=cells.min.X();x<=cells.max.X();x++)
|
||||
for (int y=cells.min.Y();y<=cells.max.Y();y++)
|
||||
for (int z=cells.min.Z();z<=cells.max.Z();z++)
|
||||
vactive.insert(vcg::Point3i(x,y,x));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
///control the real self intersection in the mesh and returns the elements that intersect with someone
|
||||
std::vector<SimplexType*> computeSelfIntersection()
|
||||
{
|
||||
std::vector<SimplexType*> ret;
|
||||
std::set<Point3i>::iterator act;
|
||||
for (act=vactive.begin();act!=vactive.end();act++)
|
||||
{
|
||||
Point3i p=*act;
|
||||
HashingTable::IteHtable I;
|
||||
if (HTable->numElemCell(p,I)>=2)
|
||||
{
|
||||
std::vector<SimplexType*> inCell;
|
||||
inCell.clear();
|
||||
HTable->getInCellUpdated(p,inCell);
|
||||
int nelem=inCell.size();
|
||||
if (nelem>=2)
|
||||
{
|
||||
//test combinations of elements
|
||||
for (int i=0;i<nelem-1;i++)
|
||||
for (int j=i+1;j<nelem;j++)
|
||||
if ((!inCell[i]->IsD())&&(!inCell[j]->IsD())&&(TestRealIntersection(inCell[i],inCell[j])))
|
||||
{
|
||||
ret.push_back(inCell[i]);
|
||||
ret.push_back(inCell[j]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
};
|
||||
#endif
|
|
@ -1,58 +0,0 @@
|
|||
#include <qapplication.h>
|
||||
#include <qimage.h>
|
||||
#include <segmentform.h>
|
||||
//#include <segmentator.h>
|
||||
#include <qdir.h>
|
||||
#include <qcolor.h>
|
||||
#include <SimpleGLWidget.h>
|
||||
#include <qtimer.h>
|
||||
|
||||
|
||||
Segmentator *s;
|
||||
QTimer *timer;
|
||||
|
||||
|
||||
int main( int argc, char ** argv )
|
||||
{
|
||||
s=new Segmentator();
|
||||
|
||||
//s->LoadFromDir("./venacava/","prova.txt");//to chANGE
|
||||
|
||||
//s->InitSegmentation(0.5,0.2,20,10.f);
|
||||
|
||||
QApplication a( argc, argv );
|
||||
|
||||
SegmentForm w;
|
||||
w.show();
|
||||
|
||||
//assign pointer to pricipal form
|
||||
w.simpleGLWidget1->w=&w;
|
||||
|
||||
|
||||
#ifdef _TORUS
|
||||
//w.simpleGLWidget1->SetExtractionParameters();
|
||||
//s->SetSegmentParameters(10,0.5f,0.2f,0.8f,0.4f,3.f,vcg::Point3f(1.f,1.f,1.f),1000,30);
|
||||
s->SetSegmentParameters(10,0.5f,0.6f,0.25f,0.2f,3.f,vcg::Point3f(1.f,1.f,1.f),1000,15);
|
||||
s->BBox().min=Point3f(-40.f,-40.f,-40.f);
|
||||
s->BBox().max=Point3f(40.f,40.f,40.f);
|
||||
s->InitSegmentation(Point3f(-25.f,0.f,0.f));
|
||||
w.simpleGLWidget1->CenterExtraction=vcg::Point3f(0.f,-25.f,0.f);
|
||||
s->gray_init=100;
|
||||
#endif
|
||||
|
||||
|
||||
/*s=new Segmentator();*/
|
||||
|
||||
//s->LoadFromDir("./venacava/","prova.txt");//to chANGE
|
||||
|
||||
////s->InitSegmentation(0.5,0.2,20,10.f);
|
||||
//w.simpleGLWidget1->path="./venacava/";
|
||||
|
||||
timer = new QTimer(w.simpleGLWidget1 );
|
||||
QTimer::connect( timer, SIGNAL(timeout()), w.simpleGLWidget1, SLOT(Update()) );
|
||||
timer->start(0); //
|
||||
|
||||
|
||||
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
|
||||
return a.exec();
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
/****************************************************************************
|
||||
** SimpleGLWidget meta object code from reading C++ file 'simpleglwidget.h'
|
||||
**
|
||||
** Created: Sat Dec 18 11:09:46 2004
|
||||
** by: The Qt MOC ($Id: moc_simpleglwidget.cpp,v 1.2 2004-12-20 17:56:01 pietroni Exp $)
|
||||
**
|
||||
** WARNING! All changes made in this file will be lost!
|
||||
*****************************************************************************/
|
||||
|
||||
#undef QT_NO_COMPAT
|
||||
#include "simpleglwidget.h"
|
||||
#include <qmetaobject.h>
|
||||
#include <qapplication.h>
|
||||
|
||||
#include <private/qucomextra_p.h>
|
||||
#if !defined(Q_MOC_OUTPUT_REVISION) || (Q_MOC_OUTPUT_REVISION != 26)
|
||||
#error "This file was generated using the moc from 3.3.2. It"
|
||||
#error "cannot be used with the include files from this version of Qt."
|
||||
#error "(The moc has changed too much.)"
|
||||
#endif
|
||||
|
||||
const char *SimpleGLWidget::className() const
|
||||
{
|
||||
return "SimpleGLWidget";
|
||||
}
|
||||
|
||||
QMetaObject *SimpleGLWidget::metaObj = 0;
|
||||
static QMetaObjectCleanUp cleanUp_SimpleGLWidget( "SimpleGLWidget", &SimpleGLWidget::staticMetaObject );
|
||||
|
||||
#ifndef QT_NO_TRANSLATION
|
||||
QString SimpleGLWidget::tr( const char *s, const char *c )
|
||||
{
|
||||
if ( qApp )
|
||||
return qApp->translate( "SimpleGLWidget", s, c, QApplication::DefaultCodec );
|
||||
else
|
||||
return QString::fromLatin1( s );
|
||||
}
|
||||
#ifndef QT_NO_TRANSLATION_UTF8
|
||||
QString SimpleGLWidget::trUtf8( const char *s, const char *c )
|
||||
{
|
||||
if ( qApp )
|
||||
return qApp->translate( "SimpleGLWidget", s, c, QApplication::UnicodeUTF8 );
|
||||
else
|
||||
return QString::fromUtf8( s );
|
||||
}
|
||||
#endif // QT_NO_TRANSLATION_UTF8
|
||||
|
||||
#endif // QT_NO_TRANSLATION
|
||||
|
||||
QMetaObject* SimpleGLWidget::staticMetaObject()
|
||||
{
|
||||
if ( metaObj )
|
||||
return metaObj;
|
||||
QMetaObject* parentObject = QGLWidget::staticMetaObject();
|
||||
static const QUMethod slot_0 = {"Open", 0, 0 };
|
||||
static const QUMethod slot_1 = {"ShowSlides", 0, 0 };
|
||||
static const QUMethod slot_2 = {"SetWire", 0, 0 };
|
||||
static const QUMethod slot_3 = {"SetShowBlocked", 0, 0 };
|
||||
static const QUMethod slot_4 = {"ShowExternalForces", 0, 0 };
|
||||
static const QUMethod slot_5 = {"ShowInternalForces", 0, 0 };
|
||||
static const QUMethod slot_6 = {"ShowResultForces", 0, 0 };
|
||||
static const QUMethod slot_7 = {"Smooth", 0, 0 };
|
||||
static const QUMethod slot_8 = {"SavePly", 0, 0 };
|
||||
static const QUMethod slot_9 = {"Apply", 0, 0 };
|
||||
static const QUMethod slot_10 = {"Extract", 0, 0 };
|
||||
static const QUMethod slot_11 = {"Update", 0, 0 };
|
||||
static const QUMethod slot_12 = {"Clear", 0, 0 };
|
||||
static const QMetaData slot_tbl[] = {
|
||||
{ "Open()", &slot_0, QMetaData::Public },
|
||||
{ "ShowSlides()", &slot_1, QMetaData::Public },
|
||||
{ "SetWire()", &slot_2, QMetaData::Public },
|
||||
{ "SetShowBlocked()", &slot_3, QMetaData::Public },
|
||||
{ "ShowExternalForces()", &slot_4, QMetaData::Public },
|
||||
{ "ShowInternalForces()", &slot_5, QMetaData::Public },
|
||||
{ "ShowResultForces()", &slot_6, QMetaData::Public },
|
||||
{ "Smooth()", &slot_7, QMetaData::Public },
|
||||
{ "SavePly()", &slot_8, QMetaData::Public },
|
||||
{ "Apply()", &slot_9, QMetaData::Public },
|
||||
{ "Extract()", &slot_10, QMetaData::Public },
|
||||
{ "Update()", &slot_11, QMetaData::Public },
|
||||
{ "Clear()", &slot_12, QMetaData::Public }
|
||||
};
|
||||
metaObj = QMetaObject::new_metaobject(
|
||||
"SimpleGLWidget", parentObject,
|
||||
slot_tbl, 13,
|
||||
0, 0,
|
||||
#ifndef QT_NO_PROPERTIES
|
||||
0, 0,
|
||||
0, 0,
|
||||
#endif // QT_NO_PROPERTIES
|
||||
0, 0 );
|
||||
cleanUp_SimpleGLWidget.setMetaObject( metaObj );
|
||||
return metaObj;
|
||||
}
|
||||
|
||||
void* SimpleGLWidget::qt_cast( const char* clname )
|
||||
{
|
||||
if ( !qstrcmp( clname, "SimpleGLWidget" ) )
|
||||
return this;
|
||||
return QGLWidget::qt_cast( clname );
|
||||
}
|
||||
|
||||
bool SimpleGLWidget::qt_invoke( int _id, QUObject* _o )
|
||||
{
|
||||
switch ( _id - staticMetaObject()->slotOffset() ) {
|
||||
case 0: Open(); break;
|
||||
case 1: ShowSlides(); break;
|
||||
case 2: SetWire(); break;
|
||||
case 3: SetShowBlocked(); break;
|
||||
case 4: ShowExternalForces(); break;
|
||||
case 5: ShowInternalForces(); break;
|
||||
case 6: ShowResultForces(); break;
|
||||
case 7: Smooth(); break;
|
||||
case 8: SavePly(); break;
|
||||
case 9: Apply(); break;
|
||||
case 10: Extract(); break;
|
||||
case 11: Update(); break;
|
||||
case 12: Clear(); break;
|
||||
default:
|
||||
return QGLWidget::qt_invoke( _id, _o );
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool SimpleGLWidget::qt_emit( int _id, QUObject* _o )
|
||||
{
|
||||
return QGLWidget::qt_emit(_id,_o);
|
||||
}
|
||||
#ifndef QT_NO_PROPERTIES
|
||||
|
||||
bool SimpleGLWidget::qt_property( int id, int f, QVariant* v)
|
||||
{
|
||||
return QGLWidget::qt_property( id, f, v);
|
||||
}
|
||||
|
||||
bool SimpleGLWidget::qt_static_property( QObject* , int , int , QVariant* ){ return FALSE; }
|
||||
#endif // QT_NO_PROPERTIES
|
|
@ -1,53 +0,0 @@
|
|||
#ifndef __PARTIALCONT__
|
||||
#define __PARTIALCONT__
|
||||
|
||||
#include<vector>
|
||||
|
||||
template <class STL_CONT, class ELEM>
|
||||
struct Partial_Container : STL_CONT
|
||||
{
|
||||
|
||||
|
||||
typedef typename STL_CONT::iterator ite_father;
|
||||
|
||||
typedef ELEM value_type;
|
||||
|
||||
public:
|
||||
struct iterator{
|
||||
|
||||
ite_father i;
|
||||
iterator (){}
|
||||
iterator (ite_father i_):i(i_){}
|
||||
|
||||
ELEM &operator *(){return *(*i);}
|
||||
|
||||
void operator ++()
|
||||
{
|
||||
///((i!=(STL_CONT::end()))&& da controllare la fine
|
||||
//while ((*i)->IsInvalid())++i;
|
||||
++i;
|
||||
}
|
||||
|
||||
iterator operator =(const iterator & oth){
|
||||
i=oth.i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator ==(const iterator & oth){
|
||||
return (i==oth.i);
|
||||
}
|
||||
bool operator !=(const iterator & oth){
|
||||
return (i!=oth.i);
|
||||
}
|
||||
|
||||
bool operator <(const iterator & oth){
|
||||
return (i<oth.i);
|
||||
}
|
||||
};
|
||||
|
||||
Partial_Container(){};
|
||||
iterator begin(){return iterator(STL_CONT::begin());}
|
||||
iterator end(){return iterator(STL_CONT::end());}
|
||||
|
||||
};
|
||||
#endif
|
|
@ -1,292 +0,0 @@
|
|||
TEMPLATE = app
|
||||
LANGUAGE = C++
|
||||
|
||||
CONFIG += qt warn_on release
|
||||
|
||||
win32:LIBS += qt-mt332.lib qtmain.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib imm32.lib winmm.lib wsock32.lib winspool.lib delayimp.lib opengl32.lib glu32.lib glew32.lib
|
||||
DEFINES += QT_NO_DEBUG _WINDOWS UNICODE WIN32 QT_DLL QT_THREAD_SUPPORT _TORUS01 _EXTENDED_MARCH1
|
||||
win32:DEFINES += QT_NO_DEBUG _WINDOWS UNICODE WIN32 QT_DLL QT_THREAD_SUPPORT _TORUS01 _EXTENDED_MARCH1
|
||||
win32:INCLUDEPATH += "$(QTDIR)\include" . "C:\Qt\3.3.2\mkspecs\win32-msvc.net" D:\sf\apps\test\segmentation3d D:\sf
|
||||
|
||||
HEADERS += simpleglwidget.h
|
||||
SOURCES += D:/sf/wrap/gui/trackmode.cpp \
|
||||
D:/sf/wrap/gui/trackball.cpp \
|
||||
D:/sf/wrap/ply/plylib.cpp \
|
||||
simpleglwidget.cpp \
|
||||
main.cpp
|
||||
FORMS = segmentform.ui \
|
||||
d:\sf\apps\test\segmentation3d\segmentform.ui
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
unix {
|
||||
UI_DIR = .ui
|
||||
MOC_DIR = .moc
|
||||
OBJECTS_DIR = .obj
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,652 +0,0 @@
|
|||
#include <SimpleGLWidget.h>
|
||||
#include <qlineedit.h>
|
||||
#include <qfiledialog.h>
|
||||
#include <qimage.h>
|
||||
#include <qdir.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <qslider.h>
|
||||
|
||||
extern Segmentator *s;
|
||||
|
||||
SimpleGLWidget::SimpleGLWidget( QWidget * parent, const char * name, const QGLWidget * shareWidget, WFlags f ):
|
||||
QGLWidget(parent, name)
|
||||
{
|
||||
|
||||
//grabKeyboard();
|
||||
_showslides=false;
|
||||
blocked=false;
|
||||
wire=true;
|
||||
extForces=false;
|
||||
intForces=false;
|
||||
resultForces=false;
|
||||
continue_int=false;
|
||||
_numslide=0;
|
||||
|
||||
TrackM.center=Point3f(0,0,0);
|
||||
TrackM.Reset();
|
||||
TrackM.radius= 100.f;
|
||||
|
||||
TrackS.center=Point3f(0,0,0);
|
||||
TrackS.Reset();
|
||||
TrackS.radius= 100.f;
|
||||
|
||||
zoom=1;
|
||||
path="";
|
||||
/*s=new Segmentator();*/
|
||||
//timer = new QTimer(this );
|
||||
//QTimer::connect( timer, SIGNAL(timeout()), this, SLOT(Update()) );
|
||||
// timer->start(0); // 2 seconds single-shot timer
|
||||
|
||||
}
|
||||
|
||||
void SimpleGLWidget::SaveMatrix()
|
||||
{
|
||||
glGetDoublev(GL_PROJECTION_MATRIX ,projection);
|
||||
glGetDoublev(GL_MODELVIEW_MATRIX ,modelMatrix);
|
||||
glGetIntegerv(GL_VIEWPORT,viewport);
|
||||
}
|
||||
|
||||
void SimpleGLWidget::LoadMatrix()
|
||||
{
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixd(projection);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadMatrixd(modelMatrix);
|
||||
}
|
||||
|
||||
//load as texture the i jpg of the directory
|
||||
void SimpleGLWidget::LoadTextureJpg(QString p,int level)
|
||||
{
|
||||
int e=glGetError();
|
||||
|
||||
QImage qI=QImage();
|
||||
QDir Qd=QDir(p);
|
||||
QString qformat;
|
||||
QString Path=QString(p);
|
||||
Qd.setNameFilter("*.jpg");
|
||||
//Qd.setNameFilter("*.bmp");
|
||||
|
||||
Qd.setSorting(QDir::Name);
|
||||
QString PathFile=Path;
|
||||
PathFile.append(Qd[level]);
|
||||
|
||||
qI.load(PathFile,qformat);
|
||||
QImage tx = QGLWidget::convertToGLFormat (qI);
|
||||
|
||||
|
||||
glGenTextures(1, &texName);
|
||||
glBindTexture(GL_TEXTURE_2D, texName);
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, 3, tx.width(), tx.height(), 0,GL_RGBA, GL_UNSIGNED_BYTE, tx.bits() );
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
|
||||
e=glGetError();
|
||||
}
|
||||
|
||||
|
||||
//load the texture corrisponding to a level
|
||||
void SimpleGLWidget::LoadTextureRaw(int level)
|
||||
{
|
||||
//glGenTextures(1, &texName);
|
||||
//glBindTexture(GL_TEXTURE_2D, texName);
|
||||
//glTexImage2D( GL_TEXTURE_2D, 0,GL_LUMINANCE, 512, 512, 0,GL_LUMINANCE, GL_SHORT, &s->V.Data[level*512*512] );
|
||||
//glEnable(GL_TEXTURE_2D);
|
||||
//glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
|
||||
//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
}
|
||||
|
||||
void SimpleGLWidget::drawSlide()
|
||||
{
|
||||
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
||||
glPolygonMode(GL_FRONT,GL_FILL);
|
||||
glMatrixMode (GL_TEXTURE);
|
||||
glLoadIdentity();
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
/*glEnable(GL_NORMALIZE);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
*/
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_LIGHT0);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
|
||||
float dx=s->BBox().DimX();
|
||||
float dy=s->BBox().DimY();
|
||||
|
||||
//to change take scale from segmentator.. better!
|
||||
float n=atof(w->S_dist->text());
|
||||
float level=((float)_numslide)*n;
|
||||
|
||||
Point3f p0=s->BBox().min;
|
||||
p0+=Point3f(0.f,0.f,level);
|
||||
|
||||
Point3f p1=p0+Point3f(dx,0.f,0.f);
|
||||
Point3f p2=p0+Point3f(dx,dy,0.f);
|
||||
Point3f p3=p0+Point3f(0.f,dy,0.f);
|
||||
|
||||
glColor3d(0.8,0.8,0.8);
|
||||
|
||||
///texture
|
||||
//_numslide
|
||||
glBegin(GL_QUADS);
|
||||
glNormal(Point3d(0,0,1));
|
||||
glTexCoord(Point3f(0,1,0));
|
||||
glVertex(p0);
|
||||
glTexCoord(Point3f(1,1,0));
|
||||
glVertex(p1);
|
||||
glTexCoord(Point3f(1,0,0));
|
||||
glVertex(p2);
|
||||
glTexCoord(Point3f(0,0,0));
|
||||
glVertex(p3);
|
||||
glEnd();
|
||||
glPopAttrib();
|
||||
|
||||
//glBegin(GL_QUADS);
|
||||
//for (int x=0;x<((s->V.dimX())-1);x++)
|
||||
// for (int y=0;y<((s->V.dimY())-1);y++)
|
||||
// {
|
||||
// glNormal(Point3d(0,0,1));
|
||||
// Point3<int> p0=Point3<int>(x,y,_numslide);
|
||||
// double color=((double)s->V.getAt(p0))/256.f;
|
||||
// glColor3d(color,color,color);
|
||||
// glVertex(p0);
|
||||
//
|
||||
// Point3<int> p1=Point3<int>(x+1,y,_numslide);
|
||||
// color=((double)s->V.getAt(p1))/256.f;
|
||||
// glColor3d(color,color,color);
|
||||
// glVertex(p1);
|
||||
//
|
||||
// Point3<int> p2=Point3<int>(x+1,y+1,_numslide);
|
||||
// color=((double)s->V.getAt(p2))/256.f;
|
||||
// glColor3d(color,color,color);
|
||||
// glVertex(p2);
|
||||
//
|
||||
// Point3<int> p3=Point3<int>(x,y+1,_numslide);
|
||||
// color=((double)s->V.getAt(p3))/256.f;
|
||||
// glColor3d(color,color,color);
|
||||
// glVertex(p3);
|
||||
// }
|
||||
//glEnd();
|
||||
}
|
||||
|
||||
void drawForces(Segmentator::Part_VertexContainer *pv,int typeForce)
|
||||
{
|
||||
Segmentator::Part_VertexContainer::iterator vi;
|
||||
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
||||
glLineWidth(0.3f);
|
||||
glDisable(GL_NORMALIZE);
|
||||
glDisable(GL_LIGHTING);
|
||||
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
|
||||
|
||||
if (typeForce==0)
|
||||
glColor3d(1,0,0);
|
||||
else
|
||||
if (typeForce==1)
|
||||
glColor3d(0,0,1);
|
||||
else
|
||||
if (typeForce==2)
|
||||
glColor3d(0,1,0);
|
||||
|
||||
for (vi=pv->begin();vi<pv->end();++vi)
|
||||
{
|
||||
glBegin(GL_LINE_LOOP);
|
||||
vcg::glVertex((*vi).P());
|
||||
if (typeForce==0)
|
||||
vcg::glVertex((*vi).P()+((*vi).IntForce()*4.f));
|
||||
else
|
||||
if (typeForce==1)
|
||||
vcg::glVertex((*vi).P()+((*vi).ExtForce()*4.f));
|
||||
else
|
||||
if (typeForce==2)
|
||||
vcg::glVertex((*vi).P()+(((*vi).ExtForce()+(*vi).IntForce())*4.f));
|
||||
glEnd();
|
||||
}
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
void SimpleGLWidget::Save()
|
||||
{
|
||||
QString filename = QFileDialog::getSaveFileName("prova.ply",
|
||||
"Ply files (*.ply)",
|
||||
this,
|
||||
"save file dialog",
|
||||
"Choose a filename to save under" );
|
||||
if (filename!=NULL)
|
||||
{
|
||||
const char *path_save=filename.ascii();
|
||||
vcg::tri::io::ExporterPLY<Segmentator::MyTriMesh>::Save((*s->m),path_save);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool TimeSelfIntersection()
|
||||
{
|
||||
static clock_t time=0;
|
||||
clock_t elapsedsecs=abs(time-clock());
|
||||
if (elapsedsecs>500)
|
||||
{
|
||||
time=clock();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//void SimpleGLWidget::WriteInfo()
|
||||
//{
|
||||
//
|
||||
// if (s!=0)
|
||||
// {
|
||||
//
|
||||
// glPushAttrib(0xffffffff);
|
||||
//
|
||||
// glEnable(GL_BLEND);
|
||||
// glBlendFunc(GL_SRC_ALPHA, GL_SRC_ALPHA);
|
||||
// glEnable(GL_LIGHTING);
|
||||
// glEnable(GL_NORMALIZE);
|
||||
// glEnable(GL_COLOR_MATERIAL);
|
||||
// glDisable(GL_CLIP_PLANE0);
|
||||
// glColor4d(0.7,0,0.7,0.6);
|
||||
//
|
||||
// glDepthRange(0.0,0.1);
|
||||
//
|
||||
// glBegin(GL_QUADS);
|
||||
// glVertex3d(-0.5,-0.5,0);
|
||||
// glVertex3d(-0.5,-0.3,0);
|
||||
// glVertex3d(0.5,-0.3,0);
|
||||
// glVertex3d(0.5,-0.5,0);
|
||||
// glEnd();
|
||||
//
|
||||
// renderText( (width() - 10) / 2, 15, "a" );
|
||||
//
|
||||
// QFont f( "arial", 12 );
|
||||
// QFontMetrics fmc( f );
|
||||
// glColor3d(1,1,1);
|
||||
//
|
||||
// QString str="";
|
||||
// int level=0;
|
||||
//
|
||||
// glDisable( GL_LIGHTING );
|
||||
// glDisable( GL_TEXTURE_2D );
|
||||
//
|
||||
// level++;
|
||||
// str.sprintf( "Triangles : %i Vertex: %i ",s->m.fn,s->m.vn);
|
||||
// renderText( 20, height() - level*20, str, f );
|
||||
// }
|
||||
//}
|
||||
|
||||
void SimpleGLWidget::SmoothMesh()
|
||||
{
|
||||
s->Smooth();
|
||||
}
|
||||
|
||||
void SimpleGLWidget::glDraw(){
|
||||
//glClearColor(0.2f,0.2f,0.2f,1.f);
|
||||
glClearColor(1.f,1.f,1.f,1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45,1,0.01,20);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(0,0,1,0,0,0,0,10,0);
|
||||
|
||||
if (s!=0){
|
||||
|
||||
glPushMatrix();
|
||||
if (_showslides)
|
||||
{
|
||||
vcg::Point3f p=Point3f((float)s->BBox().Center().V(0),(float)s->BBox().Center().V(1),(float)s->BBox().Center().V(2));
|
||||
TrackS.radius=s->BBox().Diag();
|
||||
TrackS.GetView();
|
||||
TrackS.Apply();
|
||||
TrackS.Draw();
|
||||
glScalef(1.f/s->BBox().Diag(),1.f/s->BBox().Diag(),1.f/s->BBox().Diag());
|
||||
//glScalef(GLfloat(zoom),GLfloat(zoom),GLfloat(zoom));
|
||||
glTranslate(-p);
|
||||
//save transformation matrixes
|
||||
SaveMatrix();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s->m!=NULL)
|
||||
{
|
||||
//vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(*(s->m));
|
||||
#ifndef _TORUS
|
||||
vcg::Point3f p=s->m->bbox.Center();
|
||||
#endif
|
||||
TrackM.GetView();
|
||||
TrackM.Apply();
|
||||
TrackM.Draw();
|
||||
//glScalef(1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag());
|
||||
#ifndef _TORUS
|
||||
glTranslate(-p);
|
||||
#endif
|
||||
//glTranslate(-CenterExtraction);
|
||||
//glScalef(1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag());
|
||||
}
|
||||
}
|
||||
|
||||
glEnable(GL_NORMALIZE);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
if (_showslides)
|
||||
drawSlide();
|
||||
|
||||
if (intForces)
|
||||
drawForces(&s->P_Vertex,0);
|
||||
if (extForces)
|
||||
drawForces(&s->P_Vertex,1);
|
||||
if (resultForces)
|
||||
drawForces(&s->P_Vertex,2);
|
||||
|
||||
//draw faces
|
||||
glEnable(GL_NORMALIZE);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
Segmentator::MyTriMesh::FaceIterator fi;
|
||||
|
||||
|
||||
if (wire)
|
||||
{
|
||||
glDisable(GL_NORMALIZE);
|
||||
glDisable(GL_LIGHTING);
|
||||
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
|
||||
}
|
||||
else
|
||||
glPolygonMode(GL_FRONT,GL_FILL);
|
||||
|
||||
if (s->m!=NULL)
|
||||
{
|
||||
glBegin(GL_TRIANGLES);
|
||||
for (fi=s->m->face.begin();fi<s->m->face.end();fi++)
|
||||
{
|
||||
if(!(*fi).IsD())
|
||||
{
|
||||
/*if ((!fi->V(0)->IsR())||(!fi->V(1)->IsR())||(!fi->V(2)->IsR()))
|
||||
assert(0);
|
||||
*/
|
||||
|
||||
//glColor3d(0.4,0.8,0.8);
|
||||
if (wire)
|
||||
{
|
||||
glColor3d(0,0,0);
|
||||
glLineWidth(2);
|
||||
}
|
||||
else
|
||||
glColor3d(0.4,0.8,0.8);
|
||||
if ((fi->intersected)&&(wire))
|
||||
glColor3d(1.f,0,0);
|
||||
|
||||
if (((blocked)&&(!fi->IsBlocked()))||(!blocked))
|
||||
{
|
||||
if (!wire)
|
||||
{
|
||||
vcg::glNormal(fi->V(0)->N());
|
||||
vcg::glVertex(fi->V(0)->P());
|
||||
vcg::glNormal(fi->V(1)->N());
|
||||
vcg::glVertex(fi->V(1)->P());
|
||||
vcg::glNormal(fi->V(2)->N());
|
||||
vcg::glVertex(fi->V(2)->P());
|
||||
}
|
||||
else
|
||||
{
|
||||
vcg::glVertex(fi->V(0)->P());
|
||||
vcg::glVertex(fi->V(1)->P());
|
||||
vcg::glVertex(fi->V(2)->P());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
//WriteInfo();
|
||||
|
||||
}
|
||||
QGLWidget::glDraw();
|
||||
}
|
||||
|
||||
///open the directiry and initialize dataset
|
||||
void SimpleGLWidget::OpenDirectory()
|
||||
{
|
||||
QString filename = QFileDialog::getExistingDirectory(
|
||||
".",
|
||||
this,
|
||||
"open file dialog"
|
||||
"Choose a Directory" );
|
||||
if (filename!=NULL)
|
||||
{
|
||||
rawImage=false;
|
||||
filename+="/";
|
||||
path=filename;
|
||||
const char *pa=filename.ascii();
|
||||
char *p=(char*)pa;
|
||||
s->LoadFromDir(p,"prova.txt");
|
||||
LoadTextureJpg(p,0);
|
||||
_showslides=true;
|
||||
w->SlidesButton->setOn(true);
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
///open the directiry and initialize dataset
|
||||
void SimpleGLWidget::OpenRaw()
|
||||
{
|
||||
QString filename = QFileDialog::getOpenFileName(
|
||||
"D:/Endocas/",
|
||||
"Raw Files(*.raw)",
|
||||
this,
|
||||
"open file dialog"
|
||||
"Choose a Raw file" );
|
||||
|
||||
if (filename!=NULL)
|
||||
{
|
||||
rawImage=true;
|
||||
const char *pa=filename.ascii();
|
||||
char *p=(char*)pa;
|
||||
s->LoadFromRaw(p);
|
||||
LoadTextureRaw(0);
|
||||
_showslides=true;
|
||||
w->SlidesButton->setOn(true);
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleGLWidget::resizeGL( int w, int h )
|
||||
{
|
||||
// setup viewport, projection etc.:
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadIdentity ();
|
||||
float ratio=(float)w/(float)h;
|
||||
gluPerspective(45,ratio,1,20);
|
||||
_W=w;
|
||||
_H=h;
|
||||
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
repaint();
|
||||
|
||||
}
|
||||
|
||||
void SimpleGLWidget::ClearMesh()
|
||||
{
|
||||
s->m->Clear();
|
||||
repaint();
|
||||
}
|
||||
|
||||
void SimpleGLWidget::UpdateBBMesh()
|
||||
{
|
||||
vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(*(s->m));
|
||||
}
|
||||
|
||||
void SimpleGLWidget::mousePressEvent ( QMouseEvent * e )
|
||||
{
|
||||
if (e->button()==Qt::LeftButton )
|
||||
{
|
||||
|
||||
if ((!_showslides)&&(s->m!=NULL))
|
||||
{
|
||||
/*vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(*(s->m));
|
||||
TrackM.radius=s->m->bbox.Diag();
|
||||
TrackM.center=s->m->bbox.Center();
|
||||
*/
|
||||
UpdateBBMesh();
|
||||
TrackM.MouseDown(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT);
|
||||
#ifndef _TORUS
|
||||
CenterExtraction=s->m->bbox.Center();
|
||||
#endif
|
||||
}
|
||||
else if (_showslides)
|
||||
TrackS.MouseDown(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT);
|
||||
}
|
||||
else
|
||||
//test mass spring model
|
||||
if ((e->button()==Qt::RightButton)&&(_showslides))
|
||||
{
|
||||
float winz;
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
//LoadMatrix();
|
||||
glReadPixels(e->x(),_H-e->y(),1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&winz);
|
||||
gluUnProject(e->x(),_H-e->y(),winz,modelMatrix,projection,viewport,&x,&y,&z);
|
||||
|
||||
SetExtractionParameters();
|
||||
s->InitSegmentation(Point3f(x,y,z));
|
||||
w->slider1->setValue(s->gray_init);
|
||||
|
||||
UpdateBBMesh();
|
||||
//vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(*(s->m));
|
||||
repaint();
|
||||
}
|
||||
//vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(s->m);
|
||||
}
|
||||
|
||||
void SimpleGLWidget::setColor()
|
||||
{
|
||||
s->gray_init=w->slider1->value();
|
||||
}
|
||||
|
||||
///only for debugghing
|
||||
void SimpleGLWidget::keyPressEvent(QKeyEvent *k)
|
||||
{
|
||||
s->AutoStep();
|
||||
repaint();
|
||||
}
|
||||
|
||||
void SimpleGLWidget::wheelEvent(QWheelEvent *e)
|
||||
{
|
||||
if (!_showslides)
|
||||
{
|
||||
/* zoom+=e->delta()/120.f;
|
||||
repaint();*/
|
||||
TrackM.MouseWheel(e->delta()/120.f);
|
||||
repaint();
|
||||
}
|
||||
else
|
||||
{
|
||||
int oldnum=_numslide;
|
||||
_numslide+=e->delta()/120.f;
|
||||
if ((_numslide<0)||(_numslide>=s->V.dimZ()))
|
||||
_numslide=oldnum;
|
||||
if (s!=0)
|
||||
{
|
||||
if (!rawImage)
|
||||
LoadTextureJpg(path,_numslide);
|
||||
else
|
||||
LoadTextureRaw(_numslide);
|
||||
}
|
||||
}
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
void SimpleGLWidget::mouseReleaseEvent(QMouseEvent * e )
|
||||
{
|
||||
if (!_showslides)
|
||||
TrackM.MouseUp(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT);
|
||||
else
|
||||
TrackS.MouseUp(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT);
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
void SimpleGLWidget::Step()
|
||||
{
|
||||
if ((s!=0)&&(continue_int))
|
||||
{
|
||||
s->AutoStep();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
//void SimpleGLWidget::MarchingCubesExtraction()
|
||||
// {
|
||||
// if (s!=0)
|
||||
// {
|
||||
// s->MarchingCubeExtraction();
|
||||
// repaint();
|
||||
// }
|
||||
// }
|
||||
|
||||
void SimpleGLWidget::MarchingCube()
|
||||
{
|
||||
if (s->m->fn>0)
|
||||
s->Resample();
|
||||
|
||||
//vcg::tri::io::ExporterPLY<Segmentator::MyTriMesh>::Save((*s->new_m),"d:/march.ply");
|
||||
//vcg::tri::io::ExporterPLY<Segmentator::MyTriMesh>::Save((*s->m),"d:/march.ply");
|
||||
}
|
||||
|
||||
void SimpleGLWidget::SetExtractionParameters()
|
||||
{
|
||||
float mass=atof(w->M_particles->text());
|
||||
float k_elanst=atof(w->K_elanst->text());
|
||||
float dihedral=atof(w->D_angle->text());
|
||||
float timestep=atof(w->T_step->text());
|
||||
float edge=atof(w->E_size->text());
|
||||
float tolerance=atof(w->Tolerance->text());
|
||||
float dinstance=atof(w->S_dist->text());
|
||||
//int color =atoi(w->Color->text());
|
||||
///to modify
|
||||
|
||||
s->SetSegmentParameters(tolerance,mass,k_elanst,dihedral,timestep,edge,Point3f(1.f,1.f,dinstance));
|
||||
}
|
||||
|
||||
void SimpleGLWidget::mouseMoveEvent ( QMouseEvent * e )
|
||||
{
|
||||
if (_showslides)
|
||||
TrackS.MouseMove(e->x(),_H-e->y());
|
||||
else
|
||||
TrackM.MouseMove(e->x(),_H-e->y());
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
void SimpleGLWidget::initializeGL(){
|
||||
|
||||
GLfloat f[4]={0.2f,0.2f,0.2f,1.f};
|
||||
GLfloat p[4]={3,3,5,0};
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT,f);
|
||||
glLightfv(GL_LIGHT1, GL_POSITION,p);
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE,f);
|
||||
glLightfv(GL_LIGHT1, GL_SPECULAR,f);
|
||||
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_LIGHT1);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LESS);
|
||||
glPolygonMode(GL_FRONT,GL_FILL);
|
||||
glEnable(GL_BACK);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
}
|
|
@ -1,208 +0,0 @@
|
|||
#include <GL/glew.h>
|
||||
#include <qgl.h>
|
||||
#include <wrap/gl/trimesh.h>
|
||||
#include <wrap/gui/trackball.h>
|
||||
#include <segmentator.h>
|
||||
#include <sim/tri_pde_integrator.h>
|
||||
#include <vcg/complex/trimesh/update/bounding.h>
|
||||
#include <wrap/io_trimesh/export_ply.h>
|
||||
#include <segmentform.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <qtimer.h>
|
||||
|
||||
class SimpleGLWidget: public QGLWidget{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
private :
|
||||
int _H;
|
||||
int _W;
|
||||
vcg::Trackball TrackM;
|
||||
vcg::Trackball TrackS;
|
||||
double zoom;
|
||||
GLdouble projection[16];
|
||||
GLdouble modelMatrix[16];
|
||||
GLint viewport[4];
|
||||
bool _showslides;
|
||||
int _numslide;
|
||||
bool wire;
|
||||
bool blocked;
|
||||
bool extForces;
|
||||
bool intForces;
|
||||
bool resultForces;
|
||||
bool continue_int;
|
||||
bool rawImage;
|
||||
GLuint texName;
|
||||
|
||||
//Segmentator *s;
|
||||
//QTimer *timer;
|
||||
//vcg::GlTrimesh<Segmentator::MyTriMesh> *Wrap;
|
||||
|
||||
public:
|
||||
vcg::Point3f CenterExtraction;
|
||||
QString path;
|
||||
SegmentForm *w;
|
||||
SimpleGLWidget( QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0, WFlags f = 0 );
|
||||
|
||||
virtual void glDraw();
|
||||
//virtual void paintEvent ( QPaintEvent * ) ;
|
||||
void resizeGL( int w, int h );
|
||||
virtual void mousePressEvent ( QMouseEvent * e );
|
||||
virtual void mouseReleaseEvent(QMouseEvent * e );
|
||||
virtual void mouseMoveEvent ( QMouseEvent * e );
|
||||
virtual void wheelEvent ( QWheelEvent * e );
|
||||
virtual void keyPressEvent(QKeyEvent *k);
|
||||
virtual void initializeGL();
|
||||
virtual void SaveMatrix();
|
||||
virtual void Save();
|
||||
void LoadMatrix();
|
||||
void LoadTextureJpg(QString path,int level);
|
||||
void LoadTextureRaw(int level);
|
||||
void drawSlide();
|
||||
void SmoothMesh();
|
||||
void Step();
|
||||
void SetExtractionParameters();
|
||||
void WriteInfo();
|
||||
void ClearMesh();
|
||||
void OpenDirectory();
|
||||
void OpenRaw();
|
||||
void MarchingCube();
|
||||
void UpdateBBMesh();
|
||||
void setColor();
|
||||
//void MarchingCubesExtraction();
|
||||
//virtual void keyPressEvent(QKeyEvent *qk);
|
||||
|
||||
public slots:
|
||||
|
||||
void Open()
|
||||
{
|
||||
OpenDirectory();
|
||||
}
|
||||
|
||||
void OpenRawFile()
|
||||
{
|
||||
OpenRaw();
|
||||
}
|
||||
|
||||
void ShowSlides()
|
||||
{
|
||||
_showslides=!_showslides;
|
||||
UpdateBBMesh();
|
||||
repaint();
|
||||
}
|
||||
|
||||
void SetWire()
|
||||
{
|
||||
wire=!wire;
|
||||
repaint();
|
||||
}
|
||||
|
||||
void SetShowBlocked()
|
||||
{
|
||||
blocked=!blocked;
|
||||
repaint();
|
||||
}
|
||||
|
||||
void ShowExternalForces()
|
||||
{
|
||||
extForces=!extForces;
|
||||
repaint();
|
||||
}
|
||||
|
||||
void ShowInternalForces()
|
||||
{
|
||||
intForces=!intForces;
|
||||
repaint();
|
||||
}
|
||||
|
||||
void ShowResultForces()
|
||||
{
|
||||
resultForces=!resultForces;
|
||||
repaint();
|
||||
}
|
||||
|
||||
void Smooth()
|
||||
{
|
||||
SmoothMesh();
|
||||
repaint();
|
||||
}
|
||||
|
||||
void SavePly()
|
||||
{
|
||||
Save();
|
||||
}
|
||||
|
||||
void Apply()
|
||||
{
|
||||
SetExtractionParameters();
|
||||
}
|
||||
|
||||
void Extract()
|
||||
{
|
||||
//UpdateBBMesh();
|
||||
continue_int=!continue_int;
|
||||
//if (continue_int)
|
||||
//{
|
||||
// _showslides=false;
|
||||
// w->SlidesButton->setOn(false);
|
||||
// //((SegmentForm *)this->parent())->SlidesButton->setOn(false);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// _showslides=true;
|
||||
// w->SlidesButton->setOn(true);
|
||||
// //((SegmentForm *)this->parent())->SlidesButton->setOn(true);
|
||||
//}
|
||||
repaint();
|
||||
}
|
||||
|
||||
//void Extract()
|
||||
//{
|
||||
// //UpdateBBMesh();
|
||||
// continue_int=!continue_int;
|
||||
// //if (continue_int)
|
||||
// //{
|
||||
// // _showslides=false;
|
||||
// // w->SlidesButton->setOn(false);
|
||||
// // //((SegmentForm *)this->parent())->SlidesButton->setOn(false);
|
||||
// //}
|
||||
// //else
|
||||
// //{
|
||||
// // _showslides=true;
|
||||
// // w->SlidesButton->setOn(true);
|
||||
// // //((SegmentForm *)this->parent())->SlidesButton->setOn(true);
|
||||
// //}
|
||||
// repaint();
|
||||
//}
|
||||
|
||||
void Update()
|
||||
{
|
||||
Step();
|
||||
}
|
||||
|
||||
|
||||
void Clear()
|
||||
{
|
||||
ClearMesh();
|
||||
repaint();
|
||||
}
|
||||
|
||||
void CleanMesh()
|
||||
{
|
||||
MarchingCube();
|
||||
#ifndef _TORUS
|
||||
UpdateBBMesh();
|
||||
#endif
|
||||
repaint();
|
||||
}
|
||||
/*
|
||||
void MCExtraction()
|
||||
{
|
||||
MarchingCubesExtraction();
|
||||
}*/
|
||||
|
||||
void SetSegmentColor()
|
||||
{
|
||||
setColor();
|
||||
}
|
||||
};
|
|
@ -1,519 +0,0 @@
|
|||
#ifndef _SEG3D_VOLUMEDATASET
|
||||
#define _SEG3D_VOLUMEDATASET
|
||||
|
||||
#include <qimage.h>
|
||||
#include <qdir.h>
|
||||
#include <qcolor.h>
|
||||
#include <stdio.h>
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define LimX 512
|
||||
#define LimY 512
|
||||
#define LimZ 240
|
||||
|
||||
#define dimXCell 20
|
||||
#define dimYCell 20
|
||||
#define dimZCell 20
|
||||
|
||||
#define TLBx 30
|
||||
#define TLBy 30
|
||||
#define TLBz 30
|
||||
|
||||
|
||||
template <class ScalarType>
|
||||
class Volume_Dataset_Optimized{
|
||||
|
||||
public:
|
||||
|
||||
Volume_Dataset_Optimized(){pFile=0;};
|
||||
~Volume_Dataset_Optimized(){};
|
||||
|
||||
private:
|
||||
class Cell
|
||||
{
|
||||
public:
|
||||
|
||||
void Clear()
|
||||
{
|
||||
for (int i=0;i<dimZCell;i++)
|
||||
for (int j=0;j<dimYCell;j++)
|
||||
for (int k=0;k<dimXCell;k++)
|
||||
Data[i][j][k]=0;
|
||||
}
|
||||
|
||||
ScalarType Data[dimXCell][dimYCell][dimZCell] ;
|
||||
|
||||
///operatorn to perform sorting
|
||||
inline bool operator <(const Cell &c)
|
||||
{
|
||||
return (c.timestamp>timestamp);
|
||||
}
|
||||
|
||||
///operatorn to perform sorting
|
||||
inline bool operator ==(const Cell &c)
|
||||
{
|
||||
return (c.timestamp==timestamp);
|
||||
}
|
||||
Point3i index;
|
||||
int timestamp;
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef typename std::list<Cell> StackType;
|
||||
typedef typename StackType::iterator IteStack;
|
||||
|
||||
///the class of grid of iterator to stack structure (corrispondence grid - stack)
|
||||
struct TLBelem
|
||||
{
|
||||
private:
|
||||
IteStack StackPoint;
|
||||
|
||||
public:
|
||||
|
||||
inline IteStack & I()
|
||||
{
|
||||
return StackPoint;
|
||||
}
|
||||
|
||||
bool inMem;
|
||||
};
|
||||
|
||||
FILE * pFile;
|
||||
StackType CurrStack;
|
||||
|
||||
TLBelem TLB[TLBx][TLBy][TLBz];
|
||||
Cell buffer[TLBx][TLBy] ;
|
||||
|
||||
int n_element;
|
||||
int max_element;
|
||||
int timestamp;
|
||||
|
||||
int lx;
|
||||
int ly;
|
||||
int lz;
|
||||
int TLBdx;
|
||||
int TLBdy;
|
||||
int TLBdz;
|
||||
|
||||
int timesort;
|
||||
|
||||
void SortStack()
|
||||
{
|
||||
/*std::sort<Cell>(CurrStack.begin(),CurrStack.end());
|
||||
timestamp=0;
|
||||
for (IteStack i=CurrStack.begin();i!=CurrStack.end();i++)
|
||||
(*i).timestamp=0;*/
|
||||
}
|
||||
|
||||
///allocate momory for the buffer
|
||||
void InitBuffer(Cell _buffer[TLBx][TLBy])
|
||||
{
|
||||
for (int j=0;j<TLBy;j++)
|
||||
for (int i=0;i<TLBx;i++)
|
||||
_buffer[i][j].Clear();
|
||||
}
|
||||
|
||||
///set total size of the dataset
|
||||
void Resize(int _lx,int _ly,int _lz)
|
||||
{
|
||||
lx=_lx;
|
||||
ly=_ly;
|
||||
lz=_lz;
|
||||
TLBdx=ceil(((float)_lx)/((float)dimXCell));
|
||||
TLBdy=ceil(((float)_ly)/((float)dimYCell));
|
||||
TLBdz=ceil(((float)_lz)/((float)dimZCell));
|
||||
}
|
||||
|
||||
///return a pair made by cell coordinate an coordinate relative to the cell
|
||||
std::pair<vcg::Point3i,vcg::Point3i> GetCoordinate(int x,int y, int z)
|
||||
{
|
||||
int xd=(int) x/dimXCell;
|
||||
int yd=(int) y/dimYCell;
|
||||
int zd=(int) z/dimZCell;
|
||||
|
||||
int xx= x%dimXCell;
|
||||
int yy= y%dimYCell;
|
||||
int zz= z%dimZCell;
|
||||
|
||||
return (std::pair<vcg::Point3i,vcg::Point3i> (Point3i(xd,yd,zd),Point3i(xx,yy,zz)));
|
||||
}
|
||||
|
||||
///add an element to the structure
|
||||
void Add(Cell _buffer[TLBx][TLBy],int x, int y, int z, ScalarType value)
|
||||
{
|
||||
assert(value<256);
|
||||
std::pair<vcg::Point3i,vcg::Point3i> coords=GetCoordinate(x,y,z);
|
||||
Point3i cell=coords.first;
|
||||
Point3i inter=coords.second;
|
||||
_buffer[cell.V(0)][cell.V(1)].Data[inter.V(0)][inter.V(1)][inter.V(2)]=value;
|
||||
}
|
||||
|
||||
///store a cell in the file
|
||||
void SaveCell(Cell &cell)
|
||||
{
|
||||
int size_unit=sizeof( ScalarType );
|
||||
int dim=dimXCell*dimYCell*dimZCell;
|
||||
int numwritten = fwrite(cell.Data, size_unit,dim,pFile );
|
||||
}
|
||||
|
||||
///save to file the current buffer
|
||||
void SwapBuffer(Cell _buffer[TLBx][TLBy])
|
||||
{
|
||||
for (int x=0;x<TLBdx;x++)
|
||||
for (int y=0;y<TLBdy;y++)
|
||||
SaveCell(_buffer[x][y]);
|
||||
}
|
||||
|
||||
///load a cell from file
|
||||
Cell& loadFromFile(Point3i p)
|
||||
{
|
||||
if (pFile!=0)
|
||||
{
|
||||
//8 for the 2 initial integer that describe the data set
|
||||
/*long offset=2*sizeof( ScalarType );*/
|
||||
long sizeCell=dimXCell*dimYCell*dimZCell;
|
||||
long offset=0;
|
||||
int index=(p.V(2)*TLBdx*TLBdy)+(p.V(1)*TLBdx)+p.V(0);
|
||||
offset+=sizeCell*(index)*sizeof( ScalarType );
|
||||
fseek(pFile,offset,SEEK_SET);
|
||||
Cell c;
|
||||
fread(c.Data, sizeof( ScalarType ),dimXCell*dimYCell*dimZCell,pFile);
|
||||
//assert(!ControlCell(c));
|
||||
c.index=p;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
///funtion used to control correct values of a cell use only for debbugging
|
||||
bool ControlCell(Cell &c)
|
||||
{
|
||||
for (int i=0;i<dimXCell;i++)
|
||||
for (int j=0;j<dimYCell;j++)
|
||||
for (int k=0;k<dimZCell;k++)
|
||||
if (c.Data[i][j][k]>=256)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
///build and save the strucure made fo blocks
|
||||
void LoadJpg(char *path,char *_newFile)
|
||||
{
|
||||
pFile=fopen (_newFile,"w+b");
|
||||
|
||||
//std::vector<Cell> buffer;
|
||||
/*Cell buffer[TLBx][TLBy] ;*/
|
||||
|
||||
//load first one image to see dimensions
|
||||
QImage qI=QImage();
|
||||
QDir Qd=QDir(path);
|
||||
QString qformat;
|
||||
QString Path=QString(path);
|
||||
Qd.setNameFilter("*.jpg");
|
||||
int levels=Qd.count();
|
||||
|
||||
Qd.setSorting(QDir::Name);
|
||||
QString PathFile=Path;
|
||||
|
||||
PathFile.append(Qd[0]);
|
||||
bool b=qI.load(PathFile,qformat);
|
||||
|
||||
Resize(qI.width(),qI.height(),levels);
|
||||
|
||||
InitBuffer(buffer);
|
||||
|
||||
for (int z=0;z<levels; z++)
|
||||
{
|
||||
PathFile=Path;
|
||||
PathFile.append(Qd[z]);
|
||||
qformat=qI.imageFormat(PathFile);
|
||||
bool gray=qI.allGray();
|
||||
b=qI.load(PathFile,qformat);
|
||||
|
||||
//first time I set limits of scalar field
|
||||
for (int x=0;x<qI.width();x++)
|
||||
for (int y=0;y<qI.height();y++)
|
||||
{
|
||||
QRgb color=qI.pixel(x,y);
|
||||
if (gray)//all tree component are the same
|
||||
Add(buffer,x,y,z,qRed (color));
|
||||
else ///otherwise transform
|
||||
Add(buffer,x,y,z,qGray (color));
|
||||
}
|
||||
|
||||
//if they are the last i swap the buffer
|
||||
if (((z%dimZCell)==(dimZCell-1))||(z==levels-1))
|
||||
{
|
||||
SwapBuffer(buffer);
|
||||
InitBuffer(buffer);
|
||||
}
|
||||
}
|
||||
fclose(pFile);
|
||||
pFile=0;
|
||||
}
|
||||
|
||||
///set initial size of buffer in terms of cell
|
||||
void Init(int size,char* archive,int _timeSort=3000)
|
||||
{
|
||||
timestamp=0;
|
||||
n_element=0;
|
||||
max_element=size;
|
||||
CurrStack.clear();
|
||||
pFile=fopen (archive,"r+b");
|
||||
timestamp=0;
|
||||
timesort=_timeSort;
|
||||
for(int z=0;z<TLBz;z++)
|
||||
for(int x=0;x<TLBx;x++)
|
||||
for(int y=0;y<TLBy;y++)
|
||||
TLB[x][y][z].inMem=false;
|
||||
}
|
||||
|
||||
///control if i must sort the buffer
|
||||
bool TimeSort()
|
||||
{
|
||||
static clock_t time;
|
||||
clock_t elapsedsecs=abs(time-clock());
|
||||
if (elapsedsecs>timesort)
|
||||
{
|
||||
time=clock();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline Point3i Min()//to change in case of difefrent space between sections
|
||||
{return Point3i(0,0,0);}
|
||||
|
||||
inline Point3i Max()//to change in case of difefrent space between sections
|
||||
{return Point3i(lx,ly,lz);}
|
||||
|
||||
///return the x dimension of the dataset
|
||||
inline int dimX()
|
||||
{return lx;}
|
||||
|
||||
///return the y dimension of the dataset
|
||||
inline int dimY()
|
||||
{return ly;}
|
||||
|
||||
///return the z dimension of the dataset
|
||||
inline int dimZ()
|
||||
{return lz;}
|
||||
|
||||
|
||||
///return the lenght of the diagonal
|
||||
inline float Diag()
|
||||
{
|
||||
Point3f diag=Point3f((float) _X,(float) _Y,(float) _Z);
|
||||
return (diag.Norm());
|
||||
}
|
||||
|
||||
/////erase the element not used for long time
|
||||
//void EraseLastUsed()
|
||||
//{
|
||||
// if (TimeSort())
|
||||
// SortStack();
|
||||
|
||||
// int mint=TLB[0][0][0].timestamp;
|
||||
// Point3i minElem=Point3i(0,0,0);
|
||||
|
||||
// for(int z=0;z<TLBdz;z++)
|
||||
// for(int x=0;x<TLBdx;x++)
|
||||
// for(int y=0;y<TLBdy;y++)
|
||||
// {
|
||||
// if ((TLB[x][y][z].timestamp<mint)&&(TLB[x][y][z].inMem==true))
|
||||
// {
|
||||
// mint=TLB[x][y][z].timestamp;
|
||||
// minElem=Point3i(x,y,z);
|
||||
// }
|
||||
// }
|
||||
|
||||
// TLB[minElem.V(0)][minElem.V(1)][minElem.V(2)].inMem=false;
|
||||
// IteStack ite=TLB[minElem.V(0)][minElem.V(1)][minElem.V(2)].I();
|
||||
// CurrStack.erase(ite);
|
||||
//}
|
||||
|
||||
|
||||
///return the value of the element in position point3i(i0,i1,i2)
|
||||
ScalarType getAt(Point3i p)
|
||||
{
|
||||
assert ((p.V(0)<dimX())&&(p.V(1)<dimY())&&(p.V(2)<dimZ()));
|
||||
assert ((p.V(0)>=0)&&(p.V(1)>=0)&&(p.V(2)>=0));
|
||||
|
||||
std::pair<vcg::Point3i,vcg::Point3i> co=GetCoordinate(p.V(0),p.V(1),p.V(2));
|
||||
Point3i cell=co.first;
|
||||
Point3i inter=co.second;
|
||||
TLBelem e=TLB[cell.V(0)][cell.V(1)][cell.V(2)];
|
||||
if (e.inMem)///the element is in the buffer
|
||||
{
|
||||
IteStack i=e.I();
|
||||
ScalarType ret=(*i).Data[inter.V(1)][inter.V(0)][inter.V(2)];
|
||||
timestamp++;
|
||||
(*i).timestamp=timestamp;
|
||||
return (ret);
|
||||
}
|
||||
else///element fault, must load from file ///
|
||||
{
|
||||
//insert new element in the TLB table
|
||||
Cell c=loadFromFile(cell);
|
||||
CurrStack.push_front(c);
|
||||
TLB[cell.V(0)][cell.V(1)][cell.V(2)].I()=CurrStack.begin();
|
||||
TLB[cell.V(0)][cell.V(1)][cell.V(2)].inMem=true;
|
||||
(*CurrStack.begin()).timestamp=timestamp;
|
||||
n_element++;
|
||||
///if the number of element is the meximum , then erase one with second chanche algorithm
|
||||
if (n_element>=max_element)
|
||||
{
|
||||
if (TimeSort())
|
||||
SortStack();
|
||||
CurrStack.pop_back();
|
||||
n_element--;
|
||||
}
|
||||
ScalarType ret=(*CurrStack.begin()).Data[inter.V(1)][inter.V(0)][inter.V(2)];
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <class ScalarType>
|
||||
class Volume_Dataset{
|
||||
|
||||
public:
|
||||
|
||||
Volume_Dataset(){};
|
||||
~Volume_Dataset(){};
|
||||
|
||||
ScalarType Data[LimX][LimY][LimZ] ;
|
||||
|
||||
int lx;
|
||||
int ly;
|
||||
int lz;
|
||||
|
||||
|
||||
///set total size of the dataset
|
||||
void Resize(int _lx,int _ly,int _lz)
|
||||
{
|
||||
lx=_lx;
|
||||
ly=_ly;
|
||||
lz=_lz;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/*template <class Type, int N=1>
|
||||
Type * Loadraw(char * filename){
|
||||
FILE * f = fopen(filename,"rb");
|
||||
fseek(f,0,SEEK_END);
|
||||
int l= ftell(f);
|
||||
fseek(f,0,SEEK_SET);
|
||||
Type * res = (Type *) malloc(l);
|
||||
int readed = fread(res,sizeof(Type),l/sizeof(Type),f);
|
||||
fclose(f);
|
||||
}*/
|
||||
|
||||
|
||||
void LoadRaw(char * filename){
|
||||
FILE * f = fopen(filename,"rb");
|
||||
fseek(f,0,SEEK_END);
|
||||
int l= ftell(f);
|
||||
fseek(f,0,SEEK_SET);
|
||||
int n=l/sizeof(ScalarType);
|
||||
int readed = fread(&Data,sizeof(ScalarType),l/sizeof(ScalarType),f);
|
||||
for (int i=0;i<readed;i++){
|
||||
//((unsigned short*)&Data[0][0][0])[i]/=((float)(1<<12))*(float)255;
|
||||
((short*)&Data[0][0][0])[i]+=3024;
|
||||
float a=(float)((short*)&Data[0][0][0])[i]/5324;
|
||||
((short*)&Data[0][0][0])[i]=a*255;
|
||||
}
|
||||
int levels=n/(512*512);
|
||||
Resize(512,512,levels);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
///build and save the strucure made fo blocks
|
||||
void LoadJpg(char *path)
|
||||
{
|
||||
//load first one image to see dimensions
|
||||
QImage qI=QImage();
|
||||
QDir Qd=QDir(path);
|
||||
QString qformat;
|
||||
QString Path=QString(path);
|
||||
Qd.setNameFilter("*.jpg");
|
||||
//Qd.setNameFilter("*.bmp");
|
||||
int levels=Qd.count();
|
||||
|
||||
Qd.setSorting(QDir::Name);
|
||||
QString PathFile=Path;
|
||||
|
||||
PathFile.append(Qd[0]);
|
||||
bool b=qI.load(PathFile,qformat);
|
||||
|
||||
Resize(qI.width(),qI.height(),levels);
|
||||
|
||||
|
||||
for (int z=0;z<levels; z++)
|
||||
{
|
||||
PathFile=Path;
|
||||
PathFile.append(Qd[z]);
|
||||
qformat=qI.imageFormat(PathFile);
|
||||
bool gray=qI.allGray();
|
||||
b=qI.load(PathFile,qformat);
|
||||
|
||||
//first time I set limits of scalar field
|
||||
for (int x=0;x<qI.width();x++)
|
||||
for (int y=0;y<qI.height();y++)
|
||||
{
|
||||
QRgb color=qI.pixel(x,y);
|
||||
if (gray)//all tree component are the same
|
||||
Data[x][y][z]=qRed (color);
|
||||
else ///otherwise transform
|
||||
Data[x][y][z]=qGray (color);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline Point3i Min()//to change in case of different space between sections
|
||||
{return Point3i(0,0,0);}
|
||||
|
||||
inline Point3i Max()//to change in case of different space between sections
|
||||
{return Point3i(lx,ly,lz);}
|
||||
|
||||
///return the x dimension of the dataset
|
||||
inline int dimX()
|
||||
{return lx;}
|
||||
|
||||
///return the y dimension of the dataset
|
||||
inline int dimY()
|
||||
{return ly;}
|
||||
|
||||
///return the z dimension of the dataset
|
||||
inline int dimZ()
|
||||
{return lz;}
|
||||
|
||||
///return the lenght of the diagonal
|
||||
inline float Diag()
|
||||
{
|
||||
Point3f diag=Point3f((float) _X,(float) _Y,(float) _Z);
|
||||
return (diag.Norm());
|
||||
}
|
||||
|
||||
///return the value of the element in position point3i(i0,i1,i2)
|
||||
ScalarType getAt(Point3i p)
|
||||
{
|
||||
assert ((p.V(0)<=dimX())&&(p.V(1)<=dimY())&&(p.V(2)<=dimZ()));
|
||||
assert ((p.V(0)>=0)&&(p.V(1)>=0)&&(p.V(2)>=0));
|
||||
return (Data[p.V(0)][p.V(1)][p.V(2)]);
|
||||
}
|
||||
|
||||
};
|
||||
#endif
|
Loading…
Reference in New Issue