1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | // created: 2014/11/26
|
---|
6 | // filename: Vector3Ddata.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: Class defining a 3D vector and a io_data
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 |
|
---|
18 | #include "Vector3Ddata.h"
|
---|
19 | #include <string.h>
|
---|
20 |
|
---|
21 | #define X 0
|
---|
22 | #define Y 1
|
---|
23 | #define Z 2
|
---|
24 |
|
---|
25 | using std::string;
|
---|
26 |
|
---|
27 | namespace flair { namespace core {
|
---|
28 |
|
---|
29 | /*! \class Vector3DdataElement
|
---|
30 | */
|
---|
31 | class Vector3DdataElement: public IODataElement {
|
---|
32 | public:
|
---|
33 | Vector3DdataElement(const Vector3Ddata *data,string name,uint32_t elem):IODataElement(data,name) {
|
---|
34 | this->data=data;
|
---|
35 | this->elem=elem;
|
---|
36 | size=4;
|
---|
37 | }
|
---|
38 |
|
---|
39 | ~Vector3DdataElement() {
|
---|
40 | }
|
---|
41 |
|
---|
42 | void CopyData(char* dst) const {
|
---|
43 | float value;
|
---|
44 | data->GetMutex();
|
---|
45 | switch(elem) {
|
---|
46 | case X:
|
---|
47 | value=data->x;
|
---|
48 | break;
|
---|
49 | case Y:
|
---|
50 | value=data->y;
|
---|
51 | break;
|
---|
52 | case Z:
|
---|
53 | value=data->z;
|
---|
54 | break;
|
---|
55 | default:
|
---|
56 | data->Err("type not handled\n");
|
---|
57 | value=0;
|
---|
58 | break;
|
---|
59 | }
|
---|
60 | data->ReleaseMutex();
|
---|
61 |
|
---|
62 | memcpy(dst,&value,sizeof(float));
|
---|
63 | }
|
---|
64 |
|
---|
65 | ScalarType const &GetDataType() const {
|
---|
66 | return dataType;
|
---|
67 | }
|
---|
68 |
|
---|
69 | private:
|
---|
70 | const Vector3Ddata *data;
|
---|
71 | uint32_t elem;
|
---|
72 | FloatType dataType;
|
---|
73 | };
|
---|
74 |
|
---|
75 | Vector3Ddata::Vector3Ddata(const Object* parent, string name,float x,float y,float z,uint32_t n): io_data(parent,name,n), Vector3D(x,y,z) {
|
---|
76 |
|
---|
77 | }
|
---|
78 |
|
---|
79 | Vector3Ddata::~Vector3Ddata() {
|
---|
80 |
|
---|
81 | }
|
---|
82 |
|
---|
83 | void Vector3Ddata::CopyDatas(char* dst) const {
|
---|
84 | GetMutex();
|
---|
85 | memcpy(dst,&x,sizeof(float));
|
---|
86 | memcpy(dst+sizeof(float),&y,sizeof(float));
|
---|
87 | memcpy(dst+2*sizeof(float),&z,sizeof(float));
|
---|
88 | ReleaseMutex();
|
---|
89 | }
|
---|
90 |
|
---|
91 | IODataElement* Vector3Ddata::XElement(void) const {
|
---|
92 | return new Vector3DdataElement(this,"x",X);
|
---|
93 | }
|
---|
94 |
|
---|
95 | IODataElement* Vector3Ddata::YElement(void) const {
|
---|
96 | return new Vector3DdataElement(this,"y",Y);
|
---|
97 | }
|
---|
98 |
|
---|
99 | IODataElement* Vector3Ddata::ZElement(void) const {
|
---|
100 | return new Vector3DdataElement(this,"z",Z);
|
---|
101 | }
|
---|
102 |
|
---|
103 | } // end namespace core
|
---|
104 | } // end namespace flair
|
---|