18 #include "vtkCellArray.h"
19 #include "vtkDataSetMapper.h"
20 #include "vtkElevationFilter.h"
21 #include "vtkLookupTable.h"
22 #include "vtkMatrix4x4.h"
23 #include "vtkPoints.h"
24 #include "vtkPointData.h"
26 #include "vtkPolyDataNormals.h"
27 #include "vtkProperty.h"
42 vtkLookupTable * lut = vtkLookupTable::New();
43 lut->SetHueRange(0.6,0);
44 lut->SetSaturationRange(1,1);
45 lut->SetValueRange(1,1);
47 vtkDataSetMapper * map = vtkDataSetMapper::New();
49 map->SetScalarRange(0.,1.);
52 map->SetLookupTable(lut);
54 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
57 actor_->GetProperty()->SetColor(1,1,1);
58 actor_->GetProperty()->SetPointSize(1);
69 o <<
"*********" << std::endl;
70 o <<
"a_element" << std::endl;
71 o <<
"*********" << std::endl;
72 o <<
"This is a graphical element class meant to be included in a_canvas object" << std::endl;
73 o <<
"Commands:" << std::endl;
74 o <<
"--------" << std::endl;
75 o <<
"name: set/get the name of the object" << std::endl;
76 o <<
"empty: check whether it contains data" << std::endl;
77 o <<
"color 'R' 'G' 'B': set the color [default: 1 1 1]" << std::endl;
78 o <<
"R: set/get the red value [0-1]" << std::endl;
79 o <<
"G: set/get the green value [0-1]" << std::endl;
80 o <<
"B: set/get the blue value [0-1]" << std::endl;
81 o <<
"thickness: set/get thickness of lines or points in pixel [default: 1]" << std::endl;
82 o <<
"opacity: set/get opacity of element" << std::endl;
83 o <<
"edges: show or hide the edges" << std::endl;
84 o <<
"smooth: smooth rendering" << std::endl;
85 o <<
"place 'x' 'y' 'z': position the origin of the object at the given point (absolute)" << std::endl;
86 o <<
"translate 'x' 'y' 'z': translate the object (relative)" << std::endl;
87 o <<
"open 'file': read a file containing appropriate data for the container" << std::endl;
88 o <<
"save 'file': save the data to a file" << std::endl;
89 o <<
"save_transform 'file': save the transform matrix [4x4] to a file" << std::endl;
90 o <<
"scale: set/get the scale (set the origin before scaling)" << std::endl;
91 o <<
"scale 'sx' 'sy' 'sz': scaled each dimension indenpendently" << std::endl;
92 o <<
"orient 'roll' (x) 'pitch' (y) 'yaw' (z): orient the element [in degree] (set the origin before)" << std::endl;
93 o <<
"orient: get the orientation" << std::endl;
94 o <<
"origin: set/get origin" << std::endl;
95 o <<
"small: set/get a number considered small [default: ]" << std::endl;
96 o <<
"center: get the center of gravity" << std::endl;
97 o <<
"size: get a representative size" << std::endl;
98 o <<
"bounds: get the bounds of the element" << std::endl;
99 o <<
"minx, maxx, miny, maxy, minz, maxz: get details about the bounds" << std::endl;
100 o <<
"relief x1 y1 z1 x2 y2 z2: color the element in between two points according to distance" << std::endl;
101 o <<
"steps: number of colored bands to use" << std::endl;
102 o <<
"open_scalars 'file': color elements using a scalar file" << std::endl;
103 o <<
"image 'a_image': associate a texture to project on the object" << std::endl;
104 o <<
"imageon: show the image" << std::endl;
105 o <<
"imageoff: hide the image" << std::endl;
136 for (
int i=0;i<
log0_.size(); i++)
138 std::string l =
log0_[i];
139 int pos = l.find(
"noname");
140 if (pos != std::string::npos)
141 l.replace(pos,6,
name_);
142 std::string st = l.substr(0,3);
161 std::string l = text.str();
162 std::string line = l.replace(l.find(
'\n'),1,
"");
163 log0_.push_back(line);
170 actor_->SetPosition(0.,0.,0.);
171 actor_->SetOrientation(0.,0.,0.);
172 actor_->SetScale(1.,1.,1.);
182 if ((r>=0)&&(g>=0)&&(b>=0)&&(r<=1)&&(g<=1)&&(b<=1))
186 actor_->GetProperty()->SetColor(r,g,b);
188 log_ <<
"$" <<
name_ <<
" color " << r <<
" " << g <<
" " << b << std::endl;
200 log_ <<
"$" <<
name_ <<
" R " <<
v << std::endl;
211 log_ <<
"$" <<
name_ <<
" G " <<
v << std::endl;
222 log_ <<
"$" <<
name_ <<
" B " <<
v << std::endl;
231 actor_->GetProperty()->SetPointSize(
v);
232 actor_->GetProperty()->SetLineWidth(
v);
235 log_ <<
"$" <<
name_ <<
" thickness " << v << std::endl;
242 vtkLookupTable * lut = (vtkLookupTable *)
actor_->GetMapper()->GetLookupTable();
245 unsigned int number_steps = lut->GetNumberOfTableValues();
246 for (
short i=0; i<number_steps; i++)
247 lut->SetTableValue(i,i%2,i%2,i%2);
259 vtkLookupTable * lut = (vtkLookupTable *)
actor_->GetMapper()->GetLookupTable();
262 lut->SetHueRange(0,0);
263 lut->SetSaturationRange(0,0);
264 lut->SetValueRange(0,1);
267 lut->SetHueRange(0.6,0);
268 lut->SetSaturationRange(1,1);
269 lut->SetValueRange(1,1);
276 vtkLookupTable * lut = (vtkLookupTable *)
actor_->GetMapper()->GetLookupTable();
277 double a = lut->GetHueRange()[0];
285 if ((st<0)||(st>255))
287 vtkLookupTable * lut = (vtkLookupTable *)
actor_->GetMapper()->GetLookupTable();
288 lut->SetNumberOfTableValues(st);
290 log_ <<
"$" <<
name_ <<
" steps " << st << std::endl;
296 vtkLookupTable * lut = (vtkLookupTable *)
actor_->GetMapper()->GetLookupTable();
297 return lut->GetNumberOfTableValues();
302 if ((val<0)||(val>1))
304 actor_->GetProperty()->SetOpacity(val);
307 log_ <<
"$" <<
name_ <<
" opacity " << val << std::endl;
315 actor_->GetProperty()->EdgeVisibilityOn();
316 actor_->GetProperty()->SetEdgeColor(1,1,0);
319 actor_->GetProperty()->EdgeVisibilityOff();
321 log_ <<
"$" <<
name_ <<
" edges " << val << std::endl;
327 vtkDataSetMapper * map = (vtkDataSetMapper *)(
actor_->GetMapper());
330 vtkPolyDataNormals * normals = vtkPolyDataNormals::New();
332 normals->SetFeatureAngle(20);
333 map->SetInputConnection(normals->GetOutputPort());
339 log_ <<
"$" <<
name_ <<
" smooth " << val << std::endl;
345 actor_->GetMapper()->InterpolateScalarsBeforeMappingOn();
346 vtkElevationFilter * elevation = vtkElevationFilter::New();
348 elevation->SetLowPoint(p1.x(),p1.y(),p1.z());
349 elevation->SetHighPoint(p2.x(),p2.y(),p2.z());
350 elevation->SetScalarRange(0.,1.);
351 vtkDataSetMapper * map = (vtkDataSetMapper *)(
actor_->GetMapper());
352 map->SetInputConnection(elevation->GetOutputPort());
356 log_ << p1.x() <<
" " << p1.y() <<
" " << p1.z() <<
" ";
357 log_ << p2.x() <<
" " << p2.y() <<
" " << p2.z() <<
" " << std::endl;
368 vtkFloatArray * tcoords = vtkFloatArray::New();
369 tcoords->SetNumberOfComponents(2);
371 polydata_->GetPointData()->SetTCoords(tcoords);
375 log_ <<
"$" <<
name_ <<
" image " << image.
name() << std::endl;
386 log_ <<
"$" <<
name_ <<
" image on" << std::endl;
394 log_ <<
"$" <<
name_ <<
" image off" << std::endl;
413 std::ifstream ff(file.c_str());
414 if (ff) this->
read(ff);
416 log_ <<
"$" <<
name_ <<
" open " << file << std::endl;
422 std::ofstream ff(file.c_str());
423 if (ff) this->
write(ff);
425 log_ <<
"$" <<
name_ <<
" save " << file << std::endl;
431 std::ofstream ff(file.c_str());
432 vtkMatrix4x4 * mat =
actor_->GetMatrix();
450 ff <<
"4 4" << std::endl;
451 for (
int i=0; i<4; i++)
452 ff << mat->GetElement(i,0) <<
" " << mat->GetElement(i,1) <<
" " << mat->GetElement(i,2) <<
" " << mat->GetElement(i,3) <<
" " << std::endl;
454 log_ <<
"$" <<
name_ <<
" save_transform " << file << std::endl;
460 std::ifstream
in(file.c_str());
463 vtkDoubleArray * scalars = vtkDoubleArray::New();
464 scalars->SetNumberOfComponents(1);
467 for (
int i=0; i<npts; i++)
471 scalars->InsertNextValue(val);
475 actor_->GetMapper()->InterpolateScalarsBeforeMappingOn();
476 polydata_->GetPointData()->SetScalars(scalars);
477 actor_->GetProperty()->SetInterpolationToFlat();
479 log_ <<
"$" <<
name_ <<
" open_scalars " << file << std::endl;
488 actor_->GetMapper()->Update();
489 actor_->GetMapper()->GetBounds(b);
492 std::cout <<
name_ <<
": ";
493 for (
int k=0; k<6; k++) std::cout << b[k] <<
" ";
494 std::cout << std::endl;
500 actor_->SetPosition(x,y,z);
502 log_ <<
"$" <<
name_ <<
" place " << x <<
" " << y <<
" " << z << std::endl;
510 actor_->SetPosition(x[0]+dx,x[1]+dy,x[2]+dz);
512 log_ <<
"$" <<
name_ <<
" translate " << dx <<
" " << dy <<
" " << dz << std::endl;
520 log_ <<
"$" <<
name_ <<
" origin " << x <<
" " << y <<
" " << z << std::endl;
527 actor_->SetOrientation(x,y,z);
529 log_ <<
"$" <<
name_ <<
" orient " << x <<
" " << y <<
" " << z << std::endl;
535 actor_->AddOrientation(dx,dy,dz);
537 log_ <<
"$" <<
name_ <<
" rotate " << dx <<
" " << dy <<
" " << dz << std::endl;
545 log_ <<
"$" <<
name_ <<
" scale " << s << std::endl;
551 actor_->SetScale(s1,s2,s3);
553 log_ <<
"$" <<
name_ <<
" scale " << s1 <<
" " << s2 <<
" " << s3 << std::endl;
574 actor_->GetOrientation(x);
589 return a_point((b[0]+b[1])/2.,(b[2]+b[3])/2.,(b[4]+b[5])/2.);
596 a_point p1(b[0],b[2],b[4]);
597 a_point p2(b[1],b[3],b[5]);
598 return (p2-p1).norm();
645 vtkMatrix4x4 * mat =
actor_->GetMatrix();
646 vtkPoints * points =
polydata_->GetPoints();
647 int n_pts = points->GetNumberOfPoints();
648 for (
int k = 0; k < n_pts; k++)
652 points->GetPoint(k,x);
653 mat->MultiplyPoint(x,x);
654 a_point pn(x[0],x[1],x[2]);
655 if ((pn-p).norm() <
small_)
658 double x[] = {p.x(), p.y(), p.z()};
659 points->InsertNextPoint(x);
667 std::for_each(
v.begin(),
v.end(),
d_v);
std::ostream & operator<<(std::ostream &o, const a_element &l)
std::istream & operator>>(std::istream &i, a_element &l)
void delete_vector(std::vector< a_element * > &v)
void logfile(a_text &text)
layer used by screen to draw vector graphics
void open(const std::string &file)
void log(std::ostringstream &text)
void open_scalars(const std::string &file)
void smooth(const bool val)
virtual void read(std::istream &in)
int addpoint(const a_point &p)
void dxfout(std::ostream &o) const
static const std::string help()
void translate(const double x, const double y, const double z)
void image(a_image &image)
void save(const std::string &file)
void reset_mapper_clipping()
void save_transform(const std::string &file)
std::vector< std::string > log0_
void relief(const a_point &p1, const a_point &p2)
bool greyscale() const
get the scalar viewing mode
void color(double r, double g, double b)
void opacity(const double val)
virtual std::string type() const
void rotate(const double pitch, const double roll, const double yaw)
virtual void write(std::ostream &o) const
void edges(const bool val)
vtkTexture * texture() const
void name(std::string aname)
double v(const uint32_t step, const uint32_t n)