GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GoDBTWContainerForMesh.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 "GoDBTWContainerForMesh.h"
35 
37  GoDBTWContainerForContourMesh("mesh", "track", iImgSessionID),
38  m_MeshAttributes(NULL)
39 {
41  //checker the columnsinfo
42 }
43 
44 //--------------------------------------------------------------------------
45 
46 //--------------------------------------------------------------------------
48 {
49 }
50 
51 //--------------------------------------------------------------------------
52 
53 //--------------------------------------------------------------------------
55 {
56  //Get the info for the total intensities per channel:
58 
59  std::pair< GoDBTraceInfoForTableWidget,
60  std::vector< std::string > > PairTemp;
61  size_t NumberOfChannels = this->m_ChannelsInfo.size();
62 
63  if ( this->m_ChannelsInfo.empty() )
64  {
65  std::cout << "No info for the channels" << std::endl;
66  std::cout << "Debug: In " << __FILE__ << ", line " << __LINE__;
67  std::cout << std::endl;
68  return;
69  }
70  for ( size_t i = 0; i < NumberOfChannels; i++ )
71  {
72  std::string InfoName = "TotalIntensityForChannelID";
73  InfoName += this->m_ChannelsInfo.at(i).at(1);
74  temp.InfoName = InfoName;
75  temp.ColumnNameDatabase = "Value";
76  std::string ColumnNameTableWidget = "T.I.";
77  ColumnNameTableWidget += this->m_ChannelsInfo.at(i).at(0);
78  temp.ColumnNameTableWidget = ColumnNameTableWidget;
79  temp.ToolTip = "Total Intensity For the Channel";
80  temp.TableNameDatabase = "intensity";
81  temp.TableForeignKeyDatabase = "MeshID";
82  temp.TableKeyDatabase = "MeshID";
83  m_ColumnsInfos.push_back(temp);
84  PairTemp.first = temp;
85  m_RowContainer.push_back(PairTemp);
86  temp.Clear();
87  }
88 }
89 
90 //--------------------------------------------------------------------------
91 
92 //--------------------------------------------------------------------------
94 {
96 
97  std::pair< GoDBTraceInfoForTableWidget,
98  std::vector< std::string > > PairTemp;
99 
100  //Get the info for the Volume:
101  temp.InfoName = "Volume";
102  temp.ColumnNameTableWidget = "Volume";
103  m_ColumnsInfos.push_back(temp);
104  PairTemp.first = temp;
105  m_RowContainer.push_back(PairTemp);
106  temp.Clear();
107 
108  //Get the info for the Surface Area:
109  temp.InfoName = "SurfaceArea";
110  temp.ColumnNameTableWidget = "SurfaceArea";
111  m_ColumnsInfos.push_back(temp);
112  PairTemp.first = temp;
113  m_RowContainer.push_back(PairTemp);
114  temp.Clear();
115 
116  //Get the info for CelltypeID:
117  temp.InfoName = "CellTypeID";
118  temp.ColumnNameDatabase = "CellTypeID";
119  temp.TableNameDatabase = this->m_TracesName;
120  temp.TableForeignKeyDatabase = "CellTypeID";
121  temp.TableKeyDatabase = "CellTypeID";
122  m_ColumnsInfos.push_back(temp);
123  PairTemp.first = temp;
124  m_RowContainer.push_back(PairTemp);
125  temp.Clear();
126 
127  //Get the info for the celltype name:
128  temp.ColumnNameTableWidget = "CellType";
129  temp.ColumnNameDatabase = "Name";
130  temp.TypeName = "string";
131  temp.TableNameDatabase = "celltype";
132  temp.InfoName = "CellTypeName";
133  temp.TableForeignKeyDatabase = "CellTypeID";
134  temp.TableKeyDatabase = "CellTypeID";
135  m_ColumnsInfos.push_back(temp);
136  PairTemp.first = temp;
137  m_RowContainer.push_back(PairTemp);
138  temp.Clear();
139 
140  //Get the info for SubCelltypeID:
141  temp.InfoName = "SubCellTypeID";
142  temp.ColumnNameDatabase = "SubCellularID";
143  temp.TableNameDatabase = this->m_TracesName;
144  temp.TableForeignKeyDatabase = "SubCellularID";
145  temp.TableKeyDatabase = "SubCellularID";
146  m_ColumnsInfos.push_back(temp);
147  PairTemp.first = temp;
148  m_RowContainer.push_back(PairTemp);
149  temp.Clear();
150 
151  //Get the info for the SubCellType name:
152  temp.ColumnNameTableWidget = "SubCellType";
153  temp.ColumnNameDatabase = "Name";
154  temp.TypeName = "string";
155  temp.TableNameDatabase = "subcellulartype";
156  temp.InfoName = "SubCellTypeName";
157  temp.TableForeignKeyDatabase = "SubCellularID";
158  temp.TableKeyDatabase = "SubCellularID";
159  m_ColumnsInfos.push_back(temp);
160  PairTemp.first = temp;
161  m_RowContainer.push_back(PairTemp);
162  temp.Clear();
163 }
164 
165 //--------------------------------------------------------------------------
166 
167 //--------------------------------------------------------------------------
169  vtkMySQLDatabase *iDatabaseConnector, std::vector< std::string > iVectMeshIDs)
170 {
171  std::vector< std::vector< std::string > > ValuesToFill;
172  std::vector< std::string > SelectFields;
173  this->GetValuesForIntensities(iDatabaseConnector, iVectMeshIDs, ValuesToFill,
174  SelectFields);
175  //if the mesh was just created from the visu (so there is only one):
176  if ( this->m_MeshAttributes != 0 && iVectMeshIDs.size() == 1 )
177  {
178  this->GetValuesForSurfaceVolume(ValuesToFill,
179  SelectFields);
180  }
181 
182  this->FillRowContainer(
183  ValuesToFill, SelectFields, "ColumnNameTableWidget");
184 }
185 
186 //--------------------------------------------------------------------------
187 
188 //--------------------------------------------------------------------------
190  vtkMySQLDatabase *iDatabaseConnector,
191  std::vector< std::string > iVectMeshIDs,
192  std::vector< std::vector< std::string > > & ioValuesToFill,
193  std::vector< std::string > & ioSelectFields)
194 {
195  if ( this->m_ChannelsInfo.empty() )
196  {
197  this->SetChannelsInfo(iDatabaseConnector);
198  }
199  //fill the columns names to be filled in the row container:
200  for ( unsigned int i = 0; i < this->m_ChannelsInfo.size(); i++ )
201  {
202  std::string NameTableWidgetColumn = "T.I.";
203  NameTableWidgetColumn += this->m_ChannelsInfo.at(i).at(0);
204  ioSelectFields.push_back(NameTableWidgetColumn);
205  }
206 
207  if ( iVectMeshIDs.empty() )
208  {
209  return;
210  }
211  //get the needed data from the database:
212  std::vector< std::string > SelectedFields(3);
213  SelectedFields.at(0) = "mesh.meshid";
214  SelectedFields.at(1) = "left(points,10) as points";
215  SelectedFields.at(2) = "value";
216  std::vector< std::string > ResultQuery;
217 
218  if ( iVectMeshIDs.size() == 1 )
219  {
220  this->GetIntensityValuesForOneMesh(iVectMeshIDs.front(),
221  ioValuesToFill, iDatabaseConnector);
222  }
223  else
224  {
225  std::vector< FieldWithValue > Condition(1);
226  FieldWithValue ImgSession = { "ImagingSessionID", ConvertToString< int >(this->m_ImgSessionID), "=" };
227  Condition[0] = ImgSession;
228  FieldWithValue JoinCondition = { this->m_TracesIDName, this->m_TracesIDName, "=" };
229  ResultQuery = GetAllSelectedValuesFromTwoTables(
230  iDatabaseConnector, this->m_TracesName, "intensity", SelectedFields,
231  JoinCondition, Condition);
233  ResultQuery, iVectMeshIDs, ioValuesToFill);
234  }
235 }
236 
237 //--------------------------------------------------------------------------
238 
239 //--------------------------------------------------------------------------
241  std::vector< std::vector< std::string > > & ioValuesToFill,
242  vtkMySQLDatabase *iDatabaseConnector)
243 {
244  std::vector< std::string > temp;
245  for ( unsigned int i = 0; i < this->m_ChannelsInfo.size(); i++ )
246  {
247  std::string ChannelIDValue = this->m_ChannelsInfo.at(i).at(1);
248  std::vector< FieldWithValue > Conditions(2);
249  FieldWithValue MeshID = { "MeshID", iMeshID, "=" };
250  FieldWithValue ChannelID = { "ChannelID", ChannelIDValue, "=" };
251  Conditions[0] = MeshID;
252  Conditions[1] = ChannelID;
253 
254  int ValueIntensity = FindOneID(iDatabaseConnector, "intensity",
255  "Value", Conditions);
256  if ( ValueIntensity == -1 )
257  {
258  temp.push_back("");
259  }
260  else
261  {
262  temp.push_back( ConvertToString< int >(ValueIntensity) );
263  }
264  }
265  ioValuesToFill.push_back(temp);
266 }
267 
268 //--------------------------------------------------------------------------
269 
270 //--------------------------------------------------------------------------
272  (std::vector< std::string > iResultQuery, std::vector< std::string > iVectMeshIDs,
273  std::vector< std::vector< std::string > > & ioValuesToFill)
274 {
275  std::vector< std::string >::iterator iterResult = iResultQuery.begin();
276 
277  //iResultQuery has meshid, points, value for channel0, meshid,points,
278  //value for channel1....
279  std::vector< std::string >::iterator iterMeshID = iVectMeshIDs.begin();
280 
281  size_t i;
282 
283  while ( ( iterMeshID != iVectMeshIDs.end() )
284  && ( iterResult != iResultQuery.end() ) )
285  {
286  ++iterResult;
287  std::vector< std::string > temp;
288  std::string Points = *iterResult;
289  std::string IntensityValue;
290  if ( ( Points == "0" ) || ( Points == "" ) ) //if the mesh has no points, he
291  // has no intensity
292  {
293  IntensityValue = "";
294 
295  for ( i = 0; i < this->m_ChannelsInfo.size(); i++ )
296  {
297  temp.push_back(IntensityValue);
298  }
299 
300  // iterResult = iterResult + 2;
301  if( iterResult != iResultQuery.end() )
302  {
303  ++iterResult;
304  }
305  else
306  {
307  itkGenericExceptionMacro( << "iterResult == iResultQuery" );
308  }
309  if( iterResult != iResultQuery.end() )
310  {
311  ++iterResult;
312  }
313  else
314  {
315  itkGenericExceptionMacro( << "iterResult == iResultQuery" );
316  }
317  }
318  else
319  {
320  if( iterResult != iResultQuery.end() )
321  {
322  ++iterResult;
323  }
324  else
325  {
326  itkGenericExceptionMacro( << "iterResult == iResultQuery" );
327  }
328 
329  for ( i = 0; i < this->m_ChannelsInfo.size() - 1; i++ )
330  {
331  if ( iterResult != iResultQuery.end() )
332  {
333  IntensityValue = *iterResult;
334  temp.push_back(IntensityValue);
335  }
336 
337  // iterResult = iterResult + 3;
338  if( iterResult != iResultQuery.end() )
339  {
340  ++iterResult;
341  }
342  else
343  {
344  itkGenericExceptionMacro( << "iterResult == iResultQuery" );
345  }
346  if( iterResult != iResultQuery.end() )
347  {
348  ++iterResult;
349  }
350  else
351  {
352  itkGenericExceptionMacro( << "iterResult == iResultQuery" );
353  }
354  if( iterResult != iResultQuery.end() )
355  {
356  ++iterResult;
357  }
358  else
359  {
360  itkGenericExceptionMacro( << "iterResult == iResultQuery" );
361  }
362  }
363  IntensityValue = *iterResult;
364  temp.push_back(IntensityValue);
365 
366  if( iterResult != iResultQuery.end() )
367  {
368  ++iterResult;
369  }
370  else
371  {
372  itkGenericExceptionMacro( << "iterResult == iResultQuery" );
373  }
374  }
375  ioValuesToFill.push_back(temp);
376  ++iterMeshID;
377  }
378 }
379 
380 //--------------------------------------------------------------------------
381 
382 //--------------------------------------------------------------------------
384  vtkMySQLDatabase *iDatabaseConnector, int iMeshID)
385 {
386  std::vector< std::string > MeshIDs;
387  MeshIDs.push_back( ConvertToString< int >(iMeshID) );
388  this->FillRowContainerForMeshValues(iDatabaseConnector, MeshIDs);
389 }
390 
391 //--------------------------------------------------------------------------
392 
393 //--------------------------------------------------------------------------
395  std::vector< std::vector< std::string > > & ioValuesToFill,
396  std::vector< std::string > & ioSelectFields)
397 {
398  if ( this->m_MeshAttributes != 0 )
399  {
400  if ( ioValuesToFill.size() != 1 )
401  {
402  std::cout << "more than 1 mesh for volume and surface values" << std::endl;
403  std::cout << "Debug: In " << __FILE__ << ", line " << __LINE__;
404  std::cout << std::endl;
405  return;
406  }
407  else
408  {
409  std::vector< std::string > temp = ioValuesToFill.at(0);
410  ioSelectFields.push_back("Volume");
411  temp.push_back( ConvertToString< double >(this->m_MeshAttributes->m_Volume) );
412  ioSelectFields.push_back("SurfaceArea");
413  temp.push_back( ConvertToString< double >(this->m_MeshAttributes->m_Area) );
414  ioValuesToFill.clear();
415  ioValuesToFill.push_back(temp);
416  }
417  }
418 }
419 
420 //--------------------------------------------------------------------------
421 
422 //--------------------------------------------------------------------------
425  vtkMySQLDatabase *iDatabaseConnector, std::list<unsigned int> iListTPs)
426 {
427  GoDBTableWidgetContainer::GetContainerLoadedWithAllFromDB(iDatabaseConnector, iListTPs);
428  std::vector< std::string > VectMeshIDs;
429  if (iListTPs.empty() )
430  {
431  VectMeshIDs = ListSpecificValuesForOneColumn(
432  iDatabaseConnector, "mesh", "MeshID", "ImagingSessionID",
433  ConvertToString< unsigned int >(this->m_ImgSessionID) );
434  }
435  else
436  {
437  FieldWithValue joinCondition = {"CoordIDMin", "CoordID", "="};
438  FieldWithValue andCondition = {"ImagingSessionID", ConvertToString< unsigned int >(this->m_ImgSessionID), "="};
439  std::vector< std::string > VectorValues = ListUnsgIntToVectorString(iListTPs);
440  std::list<unsigned int> MeshIDs = GetListValuesFromTwoTablesAndCondition(
441  iDatabaseConnector, "mesh", "coordinate","MeshID", joinCondition,
442  "coordinate.TCoord", VectorValues, andCondition);
443  VectMeshIDs = ListUnsgIntToVectorString(MeshIDs);
444  }
445 
446  this->FillRowContainerForMeshValues(iDatabaseConnector, VectMeshIDs);
447  return this->m_RowContainer;
448 }
449 
450 //--------------------------------------------------------------------------
451 
452 //--------------------------------------------------------------------------
454  vtkMySQLDatabase *iDatabaseConnector)
455 {
456  if ( this->m_ChannelsInfo.empty() )
457  {
458  std::vector< std::string > SelectFields;
459  SelectFields.push_back("Name");
460  SelectFields.push_back("channel.ChannelID");
461  std::vector< std::string > JoinTablesOnTraceTable;
462  JoinTablesOnTraceTable.push_back("channel");
463  JoinTablesOnTraceTable.push_back("image.ChannelID = channel.ChannelID");
464 
466  iDatabaseConnector, "image", SelectFields, "ImagingSessionID",
467  ConvertToString< unsigned int >(this->m_ImgSessionID), JoinTablesOnTraceTable, true);
468  //this->SetSpecificColumnsInfoForMesh();
470  }
471 }
472 
473 //--------------------------------------------------------------------------
474 
475 //--------------------------------------------------------------------------
478  vtkMySQLDatabase *iDatabaseConnector, int iTraceID)
479 {
481  iTraceID);
482  this->FillRowContainerForMeshValues(iDatabaseConnector, iTraceID);
483  this->m_MeshAttributes = 0;
484  return this->m_RowContainer;
485 }
486 
487 //--------------------------------------------------------------------------
488 
489 //--------------------------------------------------------------------------
491  GoFigureMeshAttributes *iMeshAttributes)
492 {
493  this->m_MeshAttributes = iMeshAttributes;
494 }
495 
496 //--------------------------------------------------------------------------
497 
498 //--------------------------------------------------------------------------
void SetChannelsInfo(vtkMySQLDatabase *iDatabaseConnector)
get the info for the channels from the database and set the corresponding columns for the intensities...
virtual TWContainerType GetContainerForOneSpecificTrace(vtkMySQLDatabase *iDatabaseConnector, int iTraceID)
get the results of the queries and put them in the row container corresponding to all the data needed...
std::list< unsigned int > GetListValuesFromTwoTablesAndCondition(vtkMySQLDatabase *iDatabaseConnector, const std::string &iTableOne, const std::string &iTableTwo, const std::string &iColumn, const FieldWithValue &iJoinCondition, const std::string &iField, const std::vector< std::string > &iVectorValues, const FieldWithValue &iAndCondition)
std::vector< std::vector< std::string > > GetValuesFromSeveralTables(vtkMySQLDatabase *DatabaseConnector, const std::string &MainTable, const std::vector< std::string > &SelectFields, const std::string &field, const std::string &value, const std::vector< std::string > &JoinTablesOnTraceTable, bool Distinct)
GoFigureMeshAttributes * m_MeshAttributes
void GetValuesForIntensities(vtkMySQLDatabase *iDatabaseConnector, std::vector< std::string > iVectMeshIDs, std::vector< std::vector< std::string > > &ioValuesToFill, std::vector< std::string > &ioSelectFields)
get the intensities values from the database,put them in ioValuesToFill, and put the corresponding co...
This class describes the specificities of the GoDBTableWidgetContainer for contour and mesh...
virtual TWContainerType GetContainerForOneSpecificTrace(vtkMySQLDatabase *iDatabaseConnector, int iTraceID)
get the results of the queries and put them in the row container corresponding to all the data needed...
std::list< unsigned int > GetAllSelectedValuesFromTwoTables(vtkMySQLDatabase *iDatabaseConnector, const std::string &iTableOne, const std::string &iTableTwo, const std::string &iColumn, const FieldWithValue &iJoinCondition, const std::vector< FieldWithValue > &iFieldsWithValues, bool Distinct)
std::vector< std::pair< GoDBTraceInfoForTableWidget, std::vector< std::string > > > TWContainerType
void GetValuesToFillForIntensityFromQueryResults(std::vector< std::string > iResultQuery, std::vector< std::string > iVectMeshIDs, std::vector< std::vector< std::string > > &ioValuesToFill)
sort the values in iResultQuery to fill ioValuesToFill
void FillRowContainerForMeshValues(vtkMySQLDatabase *iDatabaseConnector, std::vector< std::string > iVectMeshIDs)
fill the row container with intensities values only if there is more than one mesh in the iVectmeshID...
structure to pass the column information between the Table Widget and the Database ...
virtual TWContainerType GetContainerLoadedWithAllFromDB(vtkMySQLDatabase *iDatabaseConnector, std::list< unsigned int > iListTPs=std::list< unsigned int >())
get the results of the queries and put them in the row container corresponding to all the data needed...
void GetIntensityValuesForOneMesh(std::string iMeshID, std::vector< std::vector< std::string > > &ioValuesToFill, vtkMySQLDatabase *iDatabaseConnector)
get the intensities values from the database,and put them in ioValuesToFill for only one mesh ...
std::vector< std::string > ListSpecificValuesForOneColumn(vtkMySQLDatabase *iDatabaseConnector, const std::string &TableName, const std::string &ColumnName, const std::string &field, const std::string &value, bool ExcludeZero)
SELECT ColumnName FROM TableName WHERE field = value and ColumnName &lt;&gt; 0 (if excludezero) ...
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.
void FillRowContainer(std::vector< std::vector< std::string > > iResultsFromQuery, std::vector< std::string > iSelectFields, std::string BaseOn="")
fill the columns of the row container following the vector of string containing the columns to be fil...
std::vector< GoDBTraceInfoForTableWidget > m_ColumnsInfos
void SetColumnsInfoBasedOnChannelsInfo()
add as many columns with their description as there is Channels
void SetMeshAttributes(GoFigureMeshAttributes *iMeshAttributes)
set m_MeshAttributes to iMeshAttributes, needs to be called before displaying the volume...
std::vector< std::vector< std::string > > m_ChannelsInfo
void GetValuesForSurfaceVolume(std::vector< std::vector< std::string > > &ioValuesToFill, std::vector< std::string > &ioSelectFields)
extract the volume and area values from the m_MeshAttributes,put them in ioValuesToFill and put the c...
void SetSpecificInfoForMeshTable()
add the specific info for a trace to the columns description
std::vector< std::string > ListUnsgIntToVectorString(const std::list< unsigned int > &iList)
GoDBTWContainerForMesh(int iImgSessionID)
virtual TWContainerType GetContainerLoadedWithAllFromDB(vtkMySQLDatabase *iDatabaseConnector, std::list< unsigned int > iListTPs=std::list< unsigned int >())
get the results of the queries and put them in the row container corresponding to all the data needed...