Statismo  0.10.1
 All Classes Namespaces Functions Typedefs
DataItem.hxx
1 /*
2  * DataItem.h
3  *
4  * Created by Marcel Luethi
5  *
6  * Copyright (c) 2011 University of Basel
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  *
20  * Neither the name of the project's author nor the names of its
21  * contributors may be used to endorse or promote products derived from
22  * this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
30  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 #ifndef __SAMPLE_DATA_TXX
39 #define __SAMPLE_DATA_TXX
40 
41 #include "DataItem.h"
42 
43 namespace statismo {
44 
45 
46 template <class T>
47 DataItem<T>*
48 DataItem<T>::Load(const RepresenterType* representer, const H5::Group& dsGroup) {
49  VectorType dsVector;
50  std::string sampleType = HDF5Utils::readString(dsGroup, "./sampletype");
51  DataItem* newSample = 0;
52  if (sampleType == "DataItem") {
53  newSample = new DataItem<T>(representer);
54  } else if (sampleType == "DataItemWithSurrogates") {
55  newSample = new DataItemWithSurrogates<T>(representer);
56  } else {
57  throw StatisticalModelException((std::string("Unknown sampletype in hdf5 group: ") +sampleType).c_str());
58  }
59  newSample->LoadInternal(dsGroup);
60  return newSample;
61 }
62 
63 template <class T>
64 void
65 DataItem<T>::Save(const H5::Group& dsGroup) const {
66  if (dynamic_cast<const DataItemWithSurrogates<T>* >(this) != 0) {
67  HDF5Utils::writeString(dsGroup, "./sampletype", "DataItemWithSurrogates");
68  } else {
69  HDF5Utils::writeString(dsGroup, "./sampletype", "DataItem");
70  }
71  SaveInternal(dsGroup);
72 }
73 
74 }
75 
76 #endif // __SAMPLE_DATA_TXX
A trivial representer, that does no representation at all, but works directly with vectorial data...
Definition: TrivialVectorialRepresenter.h:83
static std::string readString(const H5::CommonFG &fg, const char *name)
Definition: HDF5Utils.hxx:379
static H5::DataSet writeString(const H5::CommonFG &fg, const char *name, const std::string &s)
Definition: HDF5Utils.hxx:369