GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GoDBMeshRow.cxx
Go to the documentation of this file.
1 /*=========================================================================
2  Authors: The GoFigure Dev. Team.
3  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4 
5  Copyright (c) 2009-11, President and Fellows of Harvard College.
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13  Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16  Neither the name of the President and Fellows of Harvard College
17  nor the names of its contributors may be used to endorse or promote
18  products derived from this software without specific prior written
19  permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 =========================================================================*/
34 #include "GoDBMeshRow.h"
35 #include "GoDBColorRow.h"
37 #include "GoDBRecordSetHelper.h"
38 #include "GoDBIntensityRow.h"
40 
41 #include "vtkSmartPointer.h"
42 
43 #include <iostream>
44 
45 //-------------------------------------------------------------------------
47 {
48  this->InitializeMap();
50 }
51 
52 //-------------------------------------------------------------------------
53 
54 //-------------------------------------------------------------------------
56 {
57 }
58 
59 //-------------------------------------------------------------------------
60 GoDBMeshRow::GoDBMeshRow(vtkMySQLDatabase *DatabaseConnector,
61  vtkPolyData *TraceVisu, GoDBCoordinateRow Min, GoDBCoordinateRow Max,
62  unsigned int ImgSessionID, GoFigureMeshAttributes *iMeshAttributes) :
63  GoDBTraceRow()
64 {
65  this->InitializeMap();
66  this->SetImgSessionID(ImgSessionID);
67  this->SetTheDataFromTheVisu(DatabaseConnector, TraceVisu, Min, Max, iMeshAttributes);
68 }
69 
70 //-------------------------------------------------------------------------
71 
72 //-------------------------------------------------------------------------
73 GoDBMeshRow::GoDBMeshRow(unsigned int ImagingSessionID) :
74  GoDBTraceRow()
75 {
76  this->InitializeMap();
77  this->SetImgSessionID(ImagingSessionID);
78  this->m_MapRow["ImagingSessionID"] = ConvertToString< int >(ImagingSessionID);
79 }
80 
81 //-------------------------------------------------------------------------
82 
83 //-------------------------------------------------------------------------
84 GoDBMeshRow::GoDBMeshRow(unsigned int iExistingID,
85  vtkMySQLDatabase *iDatabaseConnector) :
86  GoDBTraceRow()
87 {
88  this->InitializeMap();
89  this->SetValuesForSpecificID(iExistingID, iDatabaseConnector);
90 }
91 
92 //-------------------------------------------------------------------------
93 
94 //-------------------------------------------------------------------------
96 {
97  this->m_TableName = iRow.m_TableName;
98  this->m_TableIDName = iRow.m_TableIDName;
100  this->m_CollectionName = iRow.m_CollectionName;
101  this->InitializeMap();
102  this->m_MapRow = iRow.m_MapRow;
103  if ( !iRow.m_NameChannelWithValues.empty() )
104  {
106  }
107 }
108 
109 //-------------------------------------------------------------------------
110 
111 //-------------------------------------------------------------------------
112 void GoDBMeshRow::SetTheDataFromTheVisu(vtkMySQLDatabase *DatabaseConnector,
113  vtkPolyData *TraceVisu,
114  GoDBCoordinateRow iCoordMin,
115  GoDBCoordinateRow iCoordMax,
116  GoFigureMeshAttributes *iMeshAttributes)
117 {
118  this->SetTheDataFromTheVisuTemplate< vtkPolyDataMySQLMeshWriter >(
119  DatabaseConnector, TraceVisu, iCoordMin, iCoordMax);
120 
121  m_NameChannelWithValues.clear();
122 
123  if ( iMeshAttributes )
124  {
125  this->m_NameChannelWithValues = iMeshAttributes->m_TotalIntensityMap;
126  }
127 }
128 
129 //-------------------------------------------------------------------------
130 
131 //-------------------------------------------------------------------------
132 void
134 {
136 
137  while ( iRowIt != iRow.ConstMapEnd() )
138  {
139  this->SetField(iRowIt->first, iRowIt->second);
140  ++iRowIt;
141  }
142 }
143 
144 //-------------------------------------------------------------------------
145 
146 //-------------------------------------------------------------------------
148 {
150  this->m_TableName = "mesh";
151  this->m_TableIDName = "meshID";
152  this->m_CollectionName = "track";
153  this->m_CollectionIDName = "trackID";
154  this->m_MapRow[this->m_TableIDName] = std::string( "0" );//ConvertToString< int >(0);
155  this->m_MapRow["CellTypeID"] = std::string( "0" );//ConvertToString< int >(0);
156  this->m_MapRow["SubCellularID"] = std::string( "0" );//ConvertToString< int >(0);
157  this->m_MapRow["trackID"] = std::string( "0" );//ConvertToString< int >(0);
158 }
159 
160 //-------------------------------------------------------------------------
161 
162 //-------------------------------------------------------------------------
163 int GoDBMeshRow::SaveInDB(vtkMySQLDatabase *DatabaseConnector)
164 {
165  int SavedMeshID = GoDBTraceRow::SaveInDBTemplate< GoDBMeshRow >(DatabaseConnector, this);
166 
167  if ( !this->m_NameChannelWithValues.empty() )
168  {
169  this->SaveInDBTotalIntensityPerChannel(DatabaseConnector,
171  }
172 
173  return SavedMeshID;
174 }
175 
176 //-------------------------------------------------------------------------
177 
178 //-------------------------------------------------------------------------
179 int GoDBMeshRow::GetCellTypeID(vtkMySQLDatabase *iDatabaseConnector,
180  std::string iCellTypeName)
181 {
182  return FindOneID(iDatabaseConnector, "celltype", "CellTypeID",
183  "Name", iCellTypeName);
184 }
185 
186 //-------------------------------------------------------------------------
187 
188 //-------------------------------------------------------------------------
189 void GoDBMeshRow::SetCellType(vtkMySQLDatabase *iDatabaseConnector,
190  std::string iCellTypeName)
191 {
192  if ( iCellTypeName != "Add a new celltype..."
193  && iCellTypeName != "Delete a celltype" )
194  {
195  this->SetField< int >( "CellTypeID",
196  GoDBMeshRow::GetCellTypeID(iDatabaseConnector, iCellTypeName) );
197  }
198 }
199 
200 //-------------------------------------------------------------------------
201 
202 //-------------------------------------------------------------------------
203 int GoDBMeshRow::GetSubCellTypeID(vtkMySQLDatabase *iDatabaseConnector,
204  std::string iSubCellTypeName)
205 {
206  return FindOneID(iDatabaseConnector, "subcellulartype", "SubCellularID",
207  "Name", iSubCellTypeName);
208 }
209 
210 //-------------------------------------------------------------------------
211 
212 //-------------------------------------------------------------------------
213 void GoDBMeshRow::SetSubCellType(vtkMySQLDatabase *iDatabaseConnector,
214  std::string iSubCellTypeName)
215 {
216  if ( iSubCellTypeName != "Add a new subcelltype..."
217  && iSubCellTypeName != "Delete a subcelltype" )
218  {
219  this->SetField< int >( "SubCellularID",
220  GoDBMeshRow::GetSubCellTypeID(iDatabaseConnector, iSubCellTypeName) );
221  }
222 }
223 
224 //-------------------------------------------------------------------------
225 
226 //-------------------------------------------------------------------------
228  vtkMySQLDatabase *DatabaseConnector,
229  boost::unordered_map< std::string, int > iNameChannelWithValues)
230 {
231  if ( this->GetMapValue("meshID") == "0" )
232  {
233  std::cout << "The mesh needs to be saved before" << std::endl;
234  return;
235  }
236  if ( this->GetMapValue("ImagingSessionID") == "0" )
237  {
238  std::cout << "The imagingSession hasn't been entered for the mesh" << std::endl;
239  }
240 
241  boost::unordered_map< std::string, int >::iterator iter = iNameChannelWithValues.begin();
242  while ( iter != iNameChannelWithValues.end() )
243  {
244  std::vector< FieldWithValue > Conditions;
245  this->AddConditions("ImagingSessionID", Conditions);
246  FieldWithValue Name = { "Name", iter->first, "=" };
247  Conditions.push_back(Name);
248  int ChannelID = FindOneID(DatabaseConnector, "channel", "ChannelID", Conditions);
249 
250  GoDBIntensityRow NewIntensity;
251  NewIntensity.SetField("ChannelID", ChannelID);
252  NewIntensity.SetField("Value", iter->second);
253  std::string strMeshID = this->GetMapValue("meshID");
254  NewIntensity.SetField( "meshID", this->GetMapValue("meshID") );
255  NewIntensity.SaveInDB(DatabaseConnector);
256  ++iter;
257  }
258 }
259 
260 //-------------------------------------------------------------------------
261 
262 //-------------------------------------------------------------------------
void SafeDownCast(GoDBTraceRow &iRow)
convert a GoDBTraceRow in GoDBMeshRow
manages a map with keys matching fields of the gofiguredatabase Intensity table and values of the map...
abstract class to be inherited by Contour,Mesh,Track and GoDBLineageRow
Definition: GoDBTraceRow.h:50
StringMapConstIterator ConstMapBegin()
Definition: GoDBRow.cxx:157
boost::unordered_map< std::string, int > m_NameChannelWithValues
Definition: GoDBMeshRow.h:156
void SetTheDataFromTheVisu(vtkMySQLDatabase *DatabaseConnector, vtkPolyData *TraceVisu, GoDBCoordinateRow iCoordMin, GoDBCoordinateRow iCoordMax, GoFigureMeshAttributes *iMeshAttributes)
std::string m_TableIDName
Definition: GoDBRow.h:225
static int GetSubCellTypeID(vtkMySQLDatabase *iDatabaseConnector, std::string iSubCellTypeName)
static method.get the SubCellTypeID base on the name of the subcelltype
int SaveInDB(vtkMySQLDatabase *DatabaseConnector)
manages a map with keys matching fields of the gofiguredatabase Coordinate table and values of the ma...
virtual void InitializeMap()
virtual pure. initialize all the values of the map
bool SetValuesForSpecificID(int ID, vtkMySQLDatabase *iDatabaseConnector)
void SaveInDBTotalIntensityPerChannel(vtkMySQLDatabase *DatabaseConnector, boost::unordered_map< std::string, int > iNameChannelWithValues)
create the intensities per channel based on the channel names and values contained in iNameChannelWit...
StringMapType::const_iterator StringMapConstIterator
Definition: GoDBRow.h:61
std::string m_TableName
Definition: GoDBRow.h:224
int FindOneID(vtkMySQLDatabase *DatabaseConnector, const std::string &TableName, const std::string &ColumnName, const std::string &field, const std::string &value)
SELECT ColumnName FROM TableName WHERE field = value.
StringMapConstIterator ConstMapEnd()
Definition: GoDBRow.cxx:166
std::string m_CollectionIDName
check in the database if the Coordinate Min adn Max already exists, if yes fill the map[&quot;CoordIDMin&quot;]...
Definition: GoDBTraceRow.h:154
void SetSubCellType(vtkMySQLDatabase *DatabaseConnector, std::string SubCellTypeName)
put the value of map[&quot;SubCelltype&quot;] to SubCellTypeName
void SetCellType(vtkMySQLDatabase *DatabaseConnector, std::string CellTypeName)
put the value of map[&quot;Celltype&quot;] to CellTypeName
void SetImgSessionID(unsigned int iImgSessionID)
set the ImagingSessionID field to iImgSessionID
void SetField(const std::string &key, const T &value)
convert the value into a string and assign it to the key in the map
Definition: GoDBRow.h:73
StringMapType m_MapRow
Definition: GoDBRow.h:223
std::string m_CollectionName
Definition: GoDBTraceRow.h:155
static int GetCellTypeID(vtkMySQLDatabase *iDatabaseConnector, std::string iCellTypeName)
static method.get the CellTypeID base on the name of the celltype
this class manages the map with the keys matching the fields of the Mesh gofiguredatabase table and v...
Definition: GoDBMeshRow.h:55
void AddConditions(const std::string &iNameOfField, std::vector< FieldWithValue > &ioFieldWithValue)
add as an element of ioFieldWithValue the name and value of the map with the key iNameOfField ...
Definition: GoDBRow.cxx:263
virtual int SaveInDB(vtkMySQLDatabase *DatabaseConnector)
save the row in the database if the TraceID is set to &quot;0&quot;, update the existing traceRow if the TraceI...
virtual void InitializeMap()
virtual pure. initialize all the values of the map
boost::unordered_map< std::string, int > m_TotalIntensityMap
std::string GetMapValue(const std::string &key)
return the value for the field map[key] after having removed the " at the beginning and at the end of...
Definition: GoDBRow.cxx:174