fw4spl
ObjectLock.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwData/ObjectLock.hpp"
8 
9 #include <fwMemory/BufferObject.hpp>
10 
11 namespace fwData
12 {
13 
14 //-----------------------------------------------------------------------------
15 
16 ObjectLock::~ObjectLock()
17 {
18  m_locks.clear();
19  m_objects.clear();
20 }
21 
22 
23 //-----------------------------------------------------------------------------
24 
25 ObjectLock::ObjectLock(const ObjectLock & objectLock)
26 {
27  m_objects = objectLock.m_objects;
28  m_locks = objectLock.m_locks;
29 }
30 
31 //-----------------------------------------------------------------------------
32 
33 ObjectLock & ObjectLock::operator=(const ObjectLock & objectLock)
34 {
35  m_locks.clear();
36  m_objects.clear();
37 
38  m_objects = objectLock.m_objects;
39  m_locks = objectLock.m_locks;
40 
41  return *this;
42 }
43 
44 //-----------------------------------------------------------------------------
45 
46 void ObjectLock::lock( ::fwData::Array::sptr array, LocksType & locks )
47 {
48  if ( array )
49  {
50  locks.push_back( array->getBufferObject()->lock() );
51  m_objects.push_back(array);
52  }
53 }
54 
55 //-----------------------------------------------------------------------------
56 
57 void ObjectLock::lock( ::fwData::Image::sptr image, LocksType & locks )
58 {
59  if ( image )
60  {
61  this->lock( image->getDataArray(), locks );
62  }
63 }
64 
65 //-----------------------------------------------------------------------------
66 
67 void ObjectLock::lock( ::fwData::Mesh::sptr mesh, LocksType & locks )
68 {
69  if ( mesh )
70  {
71  this->lock( mesh->getPointsArray(), locks );
72  this->lock( mesh->getCellDataArray(), locks );
73  this->lock( mesh->getCellDataOffsetsArray(), locks );
74  this->lock( mesh->getCellTypesArray(), locks );
75 
76  this->lock( mesh->getCellColorsArray(), locks );
77  this->lock( mesh->getPointColorsArray(), locks );
78  this->lock( mesh->getCellNormalsArray(), locks );
79  this->lock( mesh->getPointNormalsArray(), locks );
80  }
81 }
82 
83 //-----------------------------------------------------------------------------
84 
85 void ObjectLock::lock( ::fwData::Reconstruction::sptr rec, LocksType & locks )
86 {
87  if ( rec )
88  {
89  this->lock( rec->getImage(), locks );
90  this->lock( rec->getMesh(), locks );
91  }
92 }
93 
94 //-----------------------------------------------------------------------------
95 
96 ObjectLock::ObjectLock( ::fwData::Object::sptr obj )
97 {
98  ::fwData::Image::sptr image = ::fwData::Image::dynamicCast( obj );
99  ::fwData::Mesh::sptr mesh = ::fwData::Mesh::dynamicCast( obj );
100  ::fwData::Array::sptr array = ::fwData::Array::dynamicCast( obj );
101 
102  if( image )
103  {
104  this->lock( image, m_locks );
105  }
106  else if ( mesh )
107  {
108  this->lock( mesh, m_locks );
109  }
110  else if ( array )
111  {
112  this->lock( array, m_locks );
113  }
114 }
115 
116 //-----------------------------------------------------------------------------
117 
118 } // fwData
Contains the representation of the data objects used in the framework.