[2] | 1 | // %flair:license{
|
---|
[15] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[2] | 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 |
|
---|
[15] | 27 | namespace flair {
|
---|
| 28 | namespace core {
|
---|
[2] | 29 |
|
---|
[15] | 30 | /*! \class Vector3DdataElement
|
---|
| 31 | */
|
---|
| 32 | class Vector3DdataElement : public IODataElement {
|
---|
| 33 | public:
|
---|
| 34 | Vector3DdataElement(const Vector3Ddata *data, string name, uint32_t elem)
|
---|
| 35 | : IODataElement(data, name) {
|
---|
| 36 | this->data = data;
|
---|
| 37 | this->elem = elem;
|
---|
| 38 | size = 4;
|
---|
| 39 | }
|
---|
[2] | 40 |
|
---|
[15] | 41 | ~Vector3DdataElement() {}
|
---|
[2] | 42 |
|
---|
[15] | 43 | void CopyData(char *dst) const {
|
---|
| 44 | float value;
|
---|
| 45 | data->GetMutex();
|
---|
| 46 | switch (elem) {
|
---|
| 47 | case X:
|
---|
| 48 | value = data->x;
|
---|
| 49 | break;
|
---|
| 50 | case Y:
|
---|
| 51 | value = data->y;
|
---|
| 52 | break;
|
---|
| 53 | case Z:
|
---|
| 54 | value = data->z;
|
---|
| 55 | break;
|
---|
| 56 | default:
|
---|
| 57 | data->Err("type not handled\n");
|
---|
| 58 | value = 0;
|
---|
| 59 | break;
|
---|
| 60 | }
|
---|
| 61 | data->ReleaseMutex();
|
---|
[2] | 62 |
|
---|
[15] | 63 | memcpy(dst, &value, sizeof(float));
|
---|
| 64 | }
|
---|
[2] | 65 |
|
---|
[15] | 66 | ScalarType const &GetDataType() const { return dataType; }
|
---|
[2] | 67 |
|
---|
[15] | 68 | private:
|
---|
| 69 | const Vector3Ddata *data;
|
---|
| 70 | uint32_t elem;
|
---|
| 71 | FloatType dataType;
|
---|
| 72 | };
|
---|
[2] | 73 |
|
---|
[15] | 74 | Vector3Ddata::Vector3Ddata(const Object *parent, string name, float x, float y,
|
---|
| 75 | float z, uint32_t n)
|
---|
| 76 | : io_data(parent, name, n), Vector3D(x, y, z) {}
|
---|
[2] | 77 |
|
---|
[15] | 78 | Vector3Ddata::~Vector3Ddata() {}
|
---|
[2] | 79 |
|
---|
[15] | 80 | void Vector3Ddata::CopyDatas(char *dst) const {
|
---|
| 81 | GetMutex();
|
---|
| 82 | memcpy(dst, &x, sizeof(float));
|
---|
| 83 | memcpy(dst + sizeof(float), &y, sizeof(float));
|
---|
| 84 | memcpy(dst + 2 * sizeof(float), &z, sizeof(float));
|
---|
| 85 | ReleaseMutex();
|
---|
[2] | 86 | }
|
---|
| 87 |
|
---|
[15] | 88 | IODataElement *Vector3Ddata::XElement(void) const {
|
---|
| 89 | return new Vector3DdataElement(this, "x", X);
|
---|
[2] | 90 | }
|
---|
| 91 |
|
---|
[15] | 92 | IODataElement *Vector3Ddata::YElement(void) const {
|
---|
| 93 | return new Vector3DdataElement(this, "y", Y);
|
---|
[2] | 94 | }
|
---|
| 95 |
|
---|
[15] | 96 | IODataElement *Vector3Ddata::ZElement(void) const {
|
---|
| 97 | return new Vector3DdataElement(this, "z", Z);
|
---|
[2] | 98 | }
|
---|
| 99 |
|
---|
| 100 | } // end namespace core
|
---|
| 101 | } // end namespace flair
|
---|