35 #ifndef __GoDBImport_h
36 #define __GoDBImport_h
38 #include "vtkMySQLDatabase.h"
44 #include "QGoIOConfigure.h"
56 GoDBImport(std::string iServerName, std::string iLogin,
57 std::string iPassword,
int iImagingSessionID,
58 std::string iFilename,
int iCurrentTimePoint);
67 void ImportContours();
92 return this->m_NewMeshIDs;
99 return this->m_NewContourIDs;
106 return this->m_NewTracksIDs;
114 return this->m_NewContourInfoForVisu;
135 std::string FindFieldName(std::string iLine);
139 std::string GetValueForTheLine(std::string iLine);
142 bool IsLineForNumberOfEntities(std::string iLine);
146 std::string SaveNoTracesEntities(
IntMapType & ioMapColorIDs,
151 void OpenDBConnection();
153 void CloseDBConnection();
159 void SaveTracesEntities(
const IntMapType & iMapColorIDs,
161 const std::string & iLineContent,
164 bool SaveIntensities =
false);
173 void SaveIntensityForMesh(std::string & ioLineContent,
182 template<
typename T >
186 std::string LineContent;
191 for (
int i = 0; i < iNumberOfEntities; i++ )
194 LineContent = this->GetValuesFromInfile< T >(EntityToSave);
195 int OldID = atoi( EntityToSave.GetMapValue( EntityToSave.GetTableIDName() ).c_str() );
198 EntityToSave.SetField(EntityToSave.GetTableIDName(),
"0");
199 int NewID = EntityToSave.SaveInDB(this->m_DatabaseConnector);
200 ioMapMatchingIDs[OldID] = NewID;
208 template<
typename T >
211 std::string LineContent;
213 getline(this->m_InFile, LineContent);
214 std::string FieldName = this->FindFieldName(LineContent);
215 std::string ValueForField = this->GetValueForTheLine(LineContent);
216 while ( ValueForField !=
"NoValueOnTheLine" )
218 ioEntityToFill.SetField(FieldName, ValueForField);
219 getline(this->m_InFile, LineContent);
220 ValueForField = this->GetValueForTheLine(LineContent);
221 FieldName = this->FindFieldName(LineContent);
224 getline(this->m_InFile, LineContent);
231 template<
typename T >
233 std::string iFieldName, T & ioEntity)
235 typename IntMapType::const_iterator iter =
236 iMapIDs.find( atoi( ioEntity.GetMapValue(iFieldName).c_str() ) );
239 if ( iter == iMapIDs.end() )
243 int NewID = iter->second;
244 ioEntity.SetField(iFieldName, NewID);
251 template<
typename T >
257 ioEntityToSave.SetField(
258 "ImagingSessionID", this->m_ImagingSessionID);
259 this->ReplaceTheFieldWithNewIDs< T >(
260 iMapColorIDs,
"ColorID", ioEntityToSave);
261 this->ReplaceTheFieldWithNewIDs< T >(
262 iMapCoordIDs,
"CoordIDMax", ioEntityToSave);
263 this->ReplaceTheFieldWithNewIDs< T >(
264 iMapCoordIDs,
"CoordIDMin", ioEntityToSave);
265 if ( ioEntityToSave.GetCollectionIDName() !=
"NoneID" )
267 this->ReplaceTheFieldWithNewIDs< T >(
268 iMapCollectionIDs, ioEntityToSave.GetCollectionIDName(),
275 template<
typename T >
279 std::string & ioLineContent,
280 std::vector< int > & ioNewTracesIDs,
287 int NumberOfTraces = atoi( this->GetValueForTheLine(ioLineContent).c_str() );
289 getline(this->m_InFile, ioLineContent);
294 for (
int i = 0; i < NumberOfTraces; i++ )
296 ioLineContent = this->GetValuesFromInfile< T >(
299 if ( TraceToSave.GetTableName() ==
"mesh" )
301 if ( !iMapIDsSpecificOne.empty() )
303 this->ReplaceTheFieldWithNewIDs< T >(
304 iMapIDsSpecificOne,
"CellTypeID", TraceToSave);
306 if ( !iMapIDsSpecificTwo.empty() )
308 this->ReplaceTheFieldWithNewIDs< T >(
309 iMapIDsSpecificTwo,
"SubCellularID", TraceToSave);
312 this->ReplaceCommonFieldsForTraces(
313 TraceToSave, iMapColorIDs, iMapCoordIDs, iMapCollectionIDs);
314 int OldTraceID = atoi( TraceToSave.GetMapValue( TraceToSave.GetTableIDName() ).c_str() );
318 TraceToSave.SetField(TraceToSave.GetTableIDName(),
"0");
319 int NewTraceID = TraceToSave.DoesThisBoundingBoxExist(this->m_DatabaseConnector);
320 if ( NewTraceID == -1 )
322 NewTraceID = TraceToSave.SaveInDB(this->m_DatabaseConnector);
327 std::cout <<
"The trace" << OldTraceID <<
" has the same bounding box as ";
328 std::cout <<
"the existing trace " << NewTraceID;
329 std::cout <<
"so the imported contours belonging to the mesh " << OldTraceID;
330 std::cout <<
" will belong to the existing mesh " << NewTraceID << std::endl;
332 ioNewTracesIDs.push_back(NewTraceID);
333 ioMapTraceIDs[OldTraceID] = NewTraceID;
std::vector< int > GetVectorNewContourIDs()
return a vector of the IDs for the contours read from the import file and saved in the database ...
std::vector< int > m_NewLineageIDs
std::string SaveImportedEntitiesInDatabase(int iNumberOfEntities, IntMapType &ioMapMatchingIDs)
get the values from the import file,save the corresponding number of entities in the database...
void ReplaceTheFieldWithNewIDs(const IntMapType &iMapIDs, std::string iFieldName, T &ioEntity)
replace in the entity to be saved the fieldname with the new IDs created that matches the old one in ...
std::vector< int > m_NewTracksIDs
std::vector< int > GetVectorNewMeshIDs()
return a vector of the IDs for the meshes read from the import file and saved in the database ...
std::vector< int > m_NewContourIDs
std::map< int, int > IntMapType
std::string GetValuesFromInfile(T &ioEntityToFill)
Get the values from the import File to fill the corresponding GoDBRow.
ContourMeshContainer * m_NewMeshInfoForVisu
ContourMeshContainer * GetNewContourInfo()
return a vector of the info needed to add in the visu the contours read from the import file and save...
std::vector< int > m_NewMeshIDs
ContourMeshContainer * m_NewContourInfoForVisu
This class get the data of traces from a textfile and save them into the GoFigure Database...
vtkMySQLDatabase * m_DatabaseConnector
Wraps a boost::multi_index_container of ContourMeshStructure. This class intends to synchronize Conto...
void ReplaceCommonFieldsForTraces(T &ioEntityToSave, const IntMapType &iMapColorIDs, const IntMapType &iMapCoordIDs, const IntMapType &iMapCollectionIDs)
replace old IDs found in the import file with new created IDs in the trace to be saved for common fie...
void SaveTraces(const IntMapType &iMapColorIDs, const IntMapType &iMapCoordIDs, const IntMapType &iMapCollectionIDs, std::string &ioLineContent, std::vector< int > &ioNewTracesIDs, IntMapType &ioMapTraceIDs, const IntMapType &iMapIDsSpecificOne, const IntMapType &iMapIDsSpecificTwo)
std::vector< int > GetVectorNewTracksIDs()
return a vector of the IDs for the tracks read from the the import file and saved in the database ...