SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NrrdData.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 /*
30  *@file NrrdData.h
31  *@brief Interface to Gordon's Nrrd class
32  *
33  *@author
34  * David Weinstein
35  * School of Computing
36  * University of Utah
37  *@date February 2001
38  */
39 
40 #if !defined(SCI_Teem_NrrdData_h)
41 #define SCI_Teem_NrrdData_h
42 
43 #include <Core/Thread/Guard.h>
44 
46 #include <Core/Datatypes/Field.h>
47 #include <Core/Containers/LockingHandle.h>
48 #include <teem/nrrd.h>
49 
50 #include <Core/Datatypes/share.h>
51 
52 namespace SCIRun {
53 
54 /////////
55 // Structure to hold NrrdData
57 public:
58  // GROUP: public data
59  //////////
60  //
61  Nrrd *nrrd_;
62 
63  NrrdData();
64  NrrdData(Nrrd *nrrd);
65  NrrdData(LockingHandle<Datatype> data_owner);
66  NrrdData(const NrrdData&);
67  virtual ~NrrdData();
68 
69  virtual NrrdData* clone();
70 
71  virtual void io(Piostream&);
73  virtual std::string dynamic_type_name() const { return type_id.type; }
74 
75  // Separate raw files.
76  void set_embed_object(bool v) { embed_object_ = v; }
77  bool get_embed_object() { return embed_object_; }
78 
79  void set_filename( const std::string &f )
80  { nrrd_fname_ = f; embed_object_ = false; }
81  const std::string get_filename() const { return nrrd_fname_; }
82 
84 
85  // As parts of TEEM are by design not thread safe we need to enforce thread-safety
86  // on certain functionality by forcing it to run single threaded.
87  // The main issue is that error reporting uses global variables and internally
88  // global variables are used.
89 
90  static void lock_teem();
91  static void unlock_teem();
92 
93 protected:
95 
96  bool in_name_set(const std::string &s) const;
97 
98  /// Either the NrrdData owns the data or it wraps this external object.
99  LockingHandle<Datatype> data_owner_;
100 
101  // To help with pio
102  std::string nrrd_fname_;
103 
104  static Persistent *maker();
105 };
106 
107 
108 typedef LockingHandle<NrrdData> NrrdDataHandle;
109 
110 
111 // nrrd Types that we need to convert to:
112 // nrrdTypeChar,
113 // nrrdTypeUChar,
114 // nrrdTypeShort,
115 // nrrdTypeUShort,
116 // nrrdTypeInt,
117 // nrrdTypeUInt,
118 // nrrdTypeLLong,
119 // nrrdTypeULLong,
120 // nrrdTypeFloat,
121 // nrrdTypeDouble,
122 
123 
124 SCISHARE int string_to_nrrd_type(const std::string &str);
125 SCISHARE std::string nrrd_type_to_string(unsigned int ntype);
126 
127 template <class T>
128 int get_nrrd_type();
129 
130 template <>
132 
133 template <>
135 
136 template <>
138 
139 template <>
141 
142 template <>
144 
145 template <>
147 
148 template <>
150 
151 template <>
153 
154 template <>
156 
157 template <>
159 
160 template <class T>
162 {
163  return nrrdTypeDouble;
164 }
165 
166 SCISHARE void get_nrrd_compile_type( const unsigned int type,
167  std::string & typeStr,
168  std::string & typeName );
169 
170 SCISHARE double get_nrrd_value( Nrrd* nrrd,
171  unsigned int p );
172 
173 
175  public:
176  // Constructor
177  NrrdGuard();
178 
179  // Destructor
180  ~NrrdGuard();
181 };
182 
183 
184 } // end namespace SCIRun
185 
186 #endif // SCI_Teem_NrrdData_h
const std::string get_filename() const
Definition: NrrdData.h:81
virtual std::string dynamic_type_name() const
Definition: NrrdData.h:73
int get_nrrd_type< short >()
Definition: NrrdData.cc:705
int get_nrrd_type< Tensor >()
Definition: NrrdData.cc:684
Nrrd * nrrd_
Definition: NrrdData.h:61
int get_nrrd_type< int >()
Definition: NrrdData.cc:719
int string_to_nrrd_type(const std::string &str)
Definition: NrrdData.cc:814
int get_nrrd_type()
Definition: NrrdData.h:161
Definition: NrrdData.h:174
Definition: Persistent.h:89
int get_nrrd_type< unsigned char >()
Definition: NrrdData.cc:698
Definition: Persistent.h:187
#define SCISHARE
Definition: share.h:39
int get_nrrd_type< float >()
Definition: NrrdData.cc:747
static PersistentTypeID type_id
Definition: NrrdData.h:72
bool write_nrrd_
Definition: NrrdData.h:83
int get_nrrd_type< unsigned int >()
Definition: NrrdData.cc:726
int get_nrrd_type< long long >()
Definition: NrrdData.cc:733
void get_nrrd_compile_type(const unsigned int type, std::string &typeStr, std::string &typeName)
Definition: NrrdData.cc:753
Definition: NrrdData.h:56
int get_nrrd_type< unsigned short >()
Definition: NrrdData.cc:712
bool embed_object_
Definition: NrrdData.h:94
int get_nrrd_type< char >()
Definition: NrrdData.cc:691
std::string nrrd_fname_
Definition: NrrdData.h:102
double get_nrrd_value(Nrrd *nrrd, unsigned int p)
Definition: NrrdData.cc:844
v
Definition: readAllFields.py:42
LockingHandle< Datatype > data_owner_
Either the NrrdData owns the data or it wraps this external object.
Definition: NrrdData.h:99
std::string nrrd_type_to_string(unsigned int ntype)
Definition: NrrdData.cc:805
LockingHandle< NrrdData > NrrdDataHandle
Definition: NrrdData.h:108
bool get_embed_object()
Definition: NrrdData.h:77
void set_embed_object(bool v)
Definition: NrrdData.h:76
Definition: Persistent.h:64
void set_filename(const std::string &f)
Definition: NrrdData.h:79
int get_nrrd_type< unsigned long long >()
Definition: NrrdData.cc:740
Definition: PropertyManager.h:193