54 #include <dtkCoreSupport/dtkAbstractData.h>
55 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
56 #include <dtkCoreSupport/dtkAbstractProcessFactory.h>
58 #include <QDomDocument>
67 class axlWriterPrivate
70 QList<dtkAbstractData *> dataList;
71 QDomDocument *domdocument;
72 QList<QDomElement> *elements ;
74 QDomElement *sceneView ;
83 d->domdocument =
new QDomDocument() ;
84 d->elements =
new QList<QDomElement>;
93 delete d->domdocument;
102 d->dataList = dataSet;
107 d->dataList.push_back(data);
120 d->sceneView = &sceneView;
125 QFile file(filename);
127 if( !file.open(QIODevice::WriteOnly | QIODevice::Text)) {
128 QMessageBox::information(0,
"Axel",
"Error of reading",
"&Ok",0) ;
133 foreach(dtkAbstractData *data, d->dataList) {
135 bool founded =
false;
138 foreach(QString writer, dtkAbstractDataFactory::instance()->writers()) {
142 QDomElement element = this->elementByWriter(axl_writer, data);
144 if(element.hasChildNodes()) {
145 d->elements->append(element);
170 QDomElement element = this->elementByWriter(axl_writer, data);
172 if(element.hasChildNodes()) {
173 d->elements->append(element);
184 QDomElement element = this->elementByWriter(axl_writer, data);
186 if(element.hasChildNodes()) {
187 d->elements->append(element);
207 QDomElement element = this->elementByWriter(axl_writer, data);
209 if(element.hasChildNodes()) {
210 d->elements->append(element);
218 QDomElement element = this->elementByWriter(axl_writer, data);
220 if(element.hasChildNodes()) {
221 d->elements->append(element);
229 QDomElement element = this->elementByWriter(axl_writer, data);
231 if(element.hasChildNodes()) {
232 d->elements->append(element);
240 QDomElement element = this->elementByWriter(axl_writer, data);
242 if(element.hasChildNodes()) {
243 d->elements->append(element);
254 QDomElement element = this->elementByWriter(axl_writer, data);
256 if(element.hasChildNodes()) {
257 d->elements->append(element);
268 QDomElement element = this->elementByWriter(axl_writer, data);
270 if(element.hasChildNodes()) {
271 d->elements->append(element);
282 QDomElement element = this->elementByWriter(axl_writer, data);
284 if(element.hasChildNodes()) {
285 d->elements->append(element);
296 QDomElement element = this->elementByWriter(axl_writer, data);
298 if(element.hasChildNodes()) {
299 d->elements->append(element);
310 QDomElement element = this->elementByWriter(axl_writer, data);
312 if(element.hasChildNodes()) {
313 d->elements->append(element);
322 QDomElement element = this->elementByWriter(axl_writer, data);
324 if(element.hasChildNodes()) {
325 d->elements->append(element);
336 QDomElement element = this->elementByWriter(axl_writer, data);
338 if(element.hasChildNodes()) {
339 d->elements->append(element);
350 QDomElement element = this->elementByWriter(axl_writer, data);
351 d->elements->append(element);
353 if(element.hasChildNodes()) {
354 d->elements->append(element);
364 QDomElement axl = d->domdocument->createElement(
"axl");
365 d->domdocument->appendChild(axl);
367 foreach(QDomElement e, *(d->elements)){
373 axl.appendChild(*(d->sceneView));
375 QTextStream ts( &file );
376 ts << d->domdocument->toString();
386 QFile filename(file);
387 QTextStream os( &filename );
389 if( !filename.open(QIODevice::WriteOnly | QIODevice::Text)) {
390 QMessageBox::information(0,
"Axel",
"Error of reading",
"&Ok",0) ;
397 for(
int i = 0 ; i < d->dataList.size() ; i++)
403 bool founded =
false;
407 foreach(QString converter, dtkAbstractDataFactory::instance()->converters())
412 axl_converter->setData(d->dataList.at(i));
413 currentMesh = axl_converter->
toMesh();
426 axl_converter->
setData(d->dataList.at(i));
427 currentMesh = axl_converter->
toMesh();
434 if ((currentMesh = dynamic_cast<axlMesh*>(d->dataList.at(i))))
439 mesh->
append(currentMesh);
450 os <<
"# "<< file <<
"\n";
451 os <<
"# This file was created with axelModeler.\n";
452 os <<
"# Go to https://axl.inria.fr for more information.\n";
463 os << p.
x() <<
" " << p.
y() <<
" " << p.
z()<<
"\n";
468 QVector<int> face = mesh->
face(i);
471 for(
int j = 0 ; j < face.size(); j++)
473 os <<
" " << face.at(j);
494 QFile file(filename);
496 int number_SurfaceBSpline;
498 QTextStream os( &file );
500 if( !file.open(QIODevice::WriteOnly | QIODevice::Text)) {
501 QMessageBox::information(0,
"Axel",
"Error of reading",
"&Ok",0) ;
505 number_SurfaceBSpline = countAxlAbstractDataSurfaceBSpline();
507 os << number_SurfaceBSpline <<
"\n";
510 foreach(dtkAbstractData *data, d->dataList)
515 double start_u = surface->startParam_u();
516 double start_v = surface->startParam_v();
517 double end_u = surface->endParam_u();
518 double end_v = surface->endParam_v();
519 double paramCourant_u = start_u;
520 double paramCourant_v = start_v;
524 int n_u = surface->numSamples_u();
525 int n_v = surface->numSamples_v();
528 os << (n_u) * (n_v) <<
" " << (n_u - 1)*(n_v - 1) * 2 <<
"\n";
530 double interval_u = (double)(end_u - start_u) / (n_u - 1);
531 double interval_v = (double)(end_v - start_v) / (n_v - 1);
534 for(
int j = 0; j < n_v - 1; j++)
536 for(
int i = 0; i < n_u - 1; i++)
538 pointCourant = surface->eval(paramCourant_u, paramCourant_v);
540 os << pointCourant.
x() <<
" " << pointCourant.
y() <<
" " << pointCourant.
z() <<
" ";
541 os << paramCourant_u <<
" " << paramCourant_v <<
" ";
542 os << num_spline <<
"\n";
544 paramCourant_u += interval_u;
547 pointCourant = surface->eval(end_u, paramCourant_v);
549 os << pointCourant.
x() <<
" " << pointCourant.
y() <<
" " << pointCourant.
z() <<
" ";
550 os << paramCourant_u <<
" " << paramCourant_v <<
" ";
551 os << num_spline <<
"\n";
553 paramCourant_u = start_u;
554 paramCourant_v += interval_v;
557 for(
int i = 0; i < n_u - 1; i++)
559 pointCourant=surface->eval(paramCourant_u, end_v);
561 os << pointCourant.
x() <<
" " << pointCourant.
y() <<
" " << pointCourant.
z() <<
" ";
562 os << paramCourant_u <<
" " << paramCourant_v <<
" ";
563 os << num_spline <<
"\n";
565 paramCourant_u += interval_u;
572 for(
int j = 0; j < n_v - 1; j++)
574 for(
int i= 0; i <n_u - 1; i++)
579 os << ind1 <<
" " << ind1 + 1 <<
" " << ind2 <<
"\n";
581 os << ind1 + 1 <<
" " << ind2 <<
" " << ind2 + 1 <<
"\n";
591 int axlWriter::countAxlAbstractDataSurfaceBSpline()
593 int num_SurfaceBSpline = 0;
595 foreach(dtkAbstractData *data, d->dataList)
597 if(dynamic_cast<axlAbstractSurfaceBSpline *>(data))
599 ++ num_SurfaceBSpline;
603 return num_SurfaceBSpline;
608 QDomElement compositeElement = d->domdocument->createElement(
"composite");
609 compositeElement.setAttribute(
"name",composite->name());
611 QColor qcolor = composite->
color();
613 QTextStream(&color) << QString::number(qcolor.red()) <<
" "
614 << QString::number(qcolor.green()) <<
" "
615 << QString::number(qcolor.blue()) ;
616 compositeElement.setAttribute(
"color", color);
617 QString shader = composite->
shader();
618 QFileInfo shaderFileInfo(shader);
619 compositeElement.setAttribute(
"shader", shaderFileInfo.fileName());
621 for(
int i = 0; i < composite->
count(); i ++)
637 compositeElement.appendChild(setComposite(dataComposite));
641 return compositeElement;
653 if(!axl_writer->
accept(data))
656 element = axl_writer->
write(d->domdocument, data);
void setSceneToWrite(QDomElement sceneView)
Class axlPoint defines 3D points.
int face_count(void) const
bool exportOFF(const QString &file)
virtual bool accept(dtkAbstractData *data)=0
virtual QString description(void) const
void append(axlMesh *mesh)
void addDataToWrite(dtkAbstractData *dataSet)
void setData(dtkAbstractData *data)
int edge_count(void) const
void vertex(const int &ind, double vertex[3])
set vertex values of vertices with index ind.
void setDataToWrite(QList< dtkAbstractData * > dataSet)
virtual QDomElement write(QDomDocument *doc, dtkAbstractData *data)=0
bool write(const QString &filename)
virtual axlMesh * toMesh(void)
Mesh conversion.
int vertex_count(void) const
void dataSetInserted(QList< dtkAbstractData * > dataSet)
bool get(dtkAbstractData *data)
Class axlMesh defines a piecewise-linear 3D object.
bool exportTo_OFF(QString &filename)