1 /*=========================================================================
2  *
3  *  Copyright Insight Software Consortium
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *         http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkSpatialObjectProperty_cxx
19 #define itkSpatialObjectProperty_cxx
20 
21 #include "itkSpatialObjectProperty.h"
22 
23 namespace itk
24 {
25 SpatialObjectProperty
SpatialObjectProperty()26 ::SpatialObjectProperty()
27 {
28   this->Clear();
29 }
30 
31 void
32 SpatialObjectProperty
Clear(void)33 ::Clear( void )
34 {
35   m_Color.SetRed(1);
36   m_Color.SetGreen(1);
37   m_Color.SetBlue(1);
38   m_Color.SetAlpha(1);
39 
40   m_Name = "";
41 
42   m_ScalarDictionary.clear();
43   m_StringDictionary.clear();
44 }
45 
46 void
47 SpatialObjectProperty
SetColor(double r,double g,double b)48 ::SetColor(double r, double g, double b)
49 {
50   m_Color.SetRed(r);
51   m_Color.SetGreen(g);
52   m_Color.SetBlue(b);
53 }
54 
55 void
56 SpatialObjectProperty
SetRed(double r)57 ::SetRed(double r)
58 {
59   m_Color.SetRed(r);
60 }
61 
62 double
63 SpatialObjectProperty
GetRed() const64 ::GetRed() const
65 {
66   return m_Color.GetRed();
67 }
68 
69 void
70 SpatialObjectProperty
SetGreen(double g)71 ::SetGreen(double g)
72 {
73   m_Color.SetGreen(g);
74 }
75 
76 double
77 SpatialObjectProperty
GetGreen() const78 ::GetGreen() const
79 {
80   return m_Color.GetGreen();
81 }
82 
83 void
84 SpatialObjectProperty
SetBlue(double b)85 ::SetBlue(double b)
86 {
87   m_Color.SetBlue(b);
88 }
89 
90 double
91 SpatialObjectProperty
GetBlue() const92 ::GetBlue() const
93 {
94   return m_Color.GetBlue();
95 }
96 
97 void
98 SpatialObjectProperty
SetAlpha(double a)99 ::SetAlpha(double a)
100 {
101   m_Color.SetAlpha(a);
102 }
103 
104 double
105 SpatialObjectProperty
GetAlpha() const106 ::GetAlpha() const
107 {
108   return m_Color.GetAlpha();
109 }
110 
111 void
112 SpatialObjectProperty
SetTagScalarValue(const std::string & tag,double value)113 ::SetTagScalarValue( const std::string & tag, double value )
114 {
115   m_ScalarDictionary[ tag ] = value;
116 }
117 
118 void
119 SpatialObjectProperty
SetTagStringValue(const std::string & tag,const std::string & value)120 ::SetTagStringValue( const std::string & tag, const std::string & value )
121 {
122   m_StringDictionary[ tag ] = value;
123 }
124 
125 bool
126 SpatialObjectProperty
GetTagScalarValue(const std::string & tag,double & value) const127 ::GetTagScalarValue( const std::string & tag, double & value ) const
128 {
129   auto it = m_ScalarDictionary.find(tag);
130   if (it != m_ScalarDictionary.end())
131     {
132     value = it->second;
133     return true;
134     }
135   else
136     {
137     return false;
138     }
139 }
140 
141 bool
142 SpatialObjectProperty
GetTagStringValue(const std::string & tag,std::string & value) const143 ::GetTagStringValue( const std::string & tag, std::string & value) const
144 {
145   auto it = m_StringDictionary.find(tag);
146   if (it != m_StringDictionary.end())
147     {
148     value = it->second;
149     return true;
150     }
151   else
152     {
153     return false;
154     }
155 }
156 
157 std::map< std::string, double > &
158 SpatialObjectProperty
GetTagScalarDictionary()159 ::GetTagScalarDictionary()
160 {
161   return m_ScalarDictionary;
162 }
163 
164 const std::map< std::string, double > &
165 SpatialObjectProperty
GetTagScalarDictionary() const166 ::GetTagScalarDictionary() const
167 {
168   return m_ScalarDictionary;
169 }
170 
171 std::map< std::string, std::string > &
172 SpatialObjectProperty
GetTagStringDictionary()173 ::GetTagStringDictionary()
174 {
175   return m_StringDictionary;
176 }
177 
178 const std::map< std::string, std::string > &
179 SpatialObjectProperty
GetTagStringDictionary() const180 ::GetTagStringDictionary() const
181 {
182   return m_StringDictionary;
183 }
184 
185 void
186 SpatialObjectProperty
SetTagScalarDictionary(const std::map<std::string,double> & dict)187 ::SetTagScalarDictionary( const std::map< std::string, double > & dict )
188 {
189   m_ScalarDictionary = dict;
190 }
191 
192 void
193 SpatialObjectProperty
SetTagStringDictionary(const std::map<std::string,std::string> & dict)194 ::SetTagStringDictionary(const std::map< std::string, std::string > & dict )
195 {
196   m_StringDictionary = dict;
197 }
198 
199 SpatialObjectProperty::Self &
200 SpatialObjectProperty
operator =(const SpatialObjectProperty & rhs)201 ::operator=( const SpatialObjectProperty & rhs )
202 {
203   if( this != &rhs )
204     {
205     this->SetName( rhs.GetName() );
206     this->SetColor( rhs.GetColor() );
207 
208     this->SetTagScalarDictionary( rhs.GetTagScalarDictionary() );
209     this->SetTagStringDictionary( rhs.GetTagStringDictionary() );
210     }
211   return *this;
212 }
213 
214 void
215 SpatialObjectProperty
PrintSelf(std::ostream & os,Indent indent) const216 ::PrintSelf(std::ostream & os, Indent indent) const
217 {
218   os << indent << "Name: " << m_Name << std::endl;
219   os << indent << "RGBA: " << m_Color.GetRed() << " " << m_Color.GetGreen()
220     << " " << m_Color.GetBlue() << " " << m_Color.GetAlpha() << std::endl;
221   os << indent << "ScalarDictionary size: " << m_ScalarDictionary.size()
222     << std::endl;
223   os << indent << "StringDictionary size: " << m_StringDictionary.size()
224     << std::endl;
225 }
226 } // end of namespace itk
227 
228 #endif // __SpatialObjectProperty_hxx
229