Developer documentation | Axl-2.5.1

axlSphereConverter.cpp
Go to the documentation of this file.
1 /* axlSphereConverter.cpp ---
2  *
3  * Author: Julien Wintz
4  * Copyright (C) 2008-2011 - Julien Wintz, Inria.
5  * Created: Tue Jan 24 11:03:18 2012 (+0100)
6  * Version: $Id$
7  * Last-Updated: Tue Jan 24 11:27:25 2012 (+0100)
8  * By: Julien Wintz
9  * Update #: 50
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlMesh.h"
21 #include "axlSphere.h"
22 #include "axlSphereConverter.h"
23 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
24 
25 class axlSphereConverterPrivate
26 {
27 public:
28  axlSphere *data;
29 };
30 
31 axlSphereConverter::axlSphereConverter(void) : axlAbstractDataConverter(), d(new axlSphereConverterPrivate)
32 {
33  d->data = NULL;
34 }
35 
37 {
38  delete d;
39 
40  d = NULL;
41 }
42 
44 {
45  return "Converter from axlSphereConverter to axlMesh";
46 }
47 
48 QStringList axlSphereConverter::fromTypes(void) const
49 {
50  return QStringList() << "axlSphereConverter" << "axlSphere";
51 }
52 
53 QString axlSphereConverter::toType (void) const
54 {
55  return "axlMesh";
56 }
57 
59 {
60  return dtkAbstractDataFactory::instance()->registerDataConverterType("axlSphereConverter", QStringList(), "axlMesh", createaxlSphereConverter);
61 }
62 
64 {
65  if(!d->data)
66  return NULL;
67 
68  axlMesh *mesh = new axlMesh;
69 
70  double x= d->data->x(),
71  y=d->data->y(),
72  z=d->data->z(),
73  r=d->data->radius();
74  double pi=3.1415;
75  unsigned N1=50, N2=50;
76 
77  for(unsigned i=0;i<N1;i++)
78  for(unsigned j=0;j<N2;j++)
79  mesh->push_back_vertex(x+r*cos(2*pi*i/N1)*cos(2*pi*j/N2),
80  y+r*sin(2*pi*i/N1)*cos(2*pi*j/N2),
81  z+r*sin(2*pi*j/N2));
82  for(unsigned i=0;i<N1;i++)
83  for(unsigned j=0;j<N2;j++){
84  axlMesh::Face f;
85  f.push_back(i+N1*j);
86  f.push_back((i+1)%N1+N1*j);
87  f.push_back((i+1)%N1+N1*((j+1)%N2));
88  f.push_back(i+N1*((j+1)%N2));;
89  mesh->push_back_face(f);
90  }
91 
92  return mesh;
93 }
94 
95 void axlSphereConverter::setData(dtkAbstractData *data)
96 {
97  if(axlSphere *sphere = dynamic_cast<axlSphere *>(data))
98  d->data = sphere;
99 }
100 
101 dtkAbstractDataConverter *createaxlSphereConverter(void)
102 {
103  return new axlSphereConverter;
104 }
void setData(dtkAbstractData *data)
QString description(void) const
QString toType(void) const
static bool registered(void)
axlMesh * toMesh(void)
dtkAbstractDataConverter * createaxlSphereConverter(void)
QVector< int > Face
A face is a polygon represented by a loop of vertices.
Definition: axlMesh.h:58
QStringList fromTypes(void) const
Class axlSphere defines 3D spheres.
Definition: axlSphere.h:33
void push_back_face(const Face &face)
Definition: axlMesh.cpp:735
Class axlMesh defines a piecewise-linear 3D object.
Definition: axlMesh.h:41
void push_back_vertex(const double &x, const double &y, const double &z)
Add a new vertex to the mesh.
Definition: axlMesh.cpp:333