AnimatLab  2
Test
FileChart.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 #include "IMovableItemCallback.h"
9 #include "ISimGUICallback.h"
10 #include "AnimatBase.h"
11 
12 #include "Gain.h"
13 #include "Node.h"
14 #include "Link.h"
15 #include "IPhysicsMovableItem.h"
16 #include "IPhysicsBody.h"
17 #include "BoundingBox.h"
18 #include "MovableItem.h"
19 #include "BodyPart.h"
20 #include "Joint.h"
21 #include "ReceptiveField.h"
22 #include "ContactSensor.h"
23 #include "RigidBody.h"
24 #include "Structure.h"
25 #include "NeuralModule.h"
26 #include "Adapter.h"
27 #include "NervousSystem.h"
28 #include "Organism.h"
29 #include "ActivatedItem.h"
30 #include "ActivatedItemMgr.h"
31 #include "DataColumn.h"
32 #include "DataChart.h"
33 #include "FileChart.h"
34 #include "DataChartMgr.h"
35 #include "ExternalStimuliMgr.h"
36 #include "KeyFrame.h"
37 #include "SimulationRecorder.h"
38 #include "OdorType.h"
39 #include "Odor.h"
40 #include "Light.h"
41 #include "LightManager.h"
42 #include "Simulator.h"
43 
44 namespace AnimatSim
45 {
46  namespace Charting
47  {
55 {
56 }
57 
65 {
66 
67 try
68 {
69 }
70 catch(...)
71 {Std_TraceMsg(0, "Caught Error in desctructor of FileChart\r\n", "", -1, false, true);}
72 }
73 
74 std::string FileChart::Type() {return "FileChart";}
75 
85 
94 void FileChart::OutputFilename(std::string strVal)
95 {
96  if(Std_IsBlank(strVal))
97  THROW_ERROR(Al_Err_lFilenameBlank, Al_Err_strFilenameBlank);
98 
99  m_strOutputFilename = strVal;
100 }
101 
103 {
105 
106  //Now open the file stream for output.
107  oStream.open(AnimatSim::GetFilePath(m_strProjectPath, m_strOutputFilename).c_str());
108 }
109 
110 
112 {
114 
115  //Temporarry. We need to save the output file when deactivating.
116  //Later we can change this to make it more flexible. Mabey periodically
117  //dumping out the buffer once it gets full.
118  SaveOutput();
119 }
120 
122 {
124 
125  //re-open the file stream for output.
126  oStream.open(AnimatSim::GetFilePath(m_strProjectPath, m_strOutputFilename).c_str());
127 }
128 
129 void FileChart::Load(CStdXml &oXml)
130 {
131  DataChart::Load(oXml);
132 
133  oXml.IntoElem(); //Into FileChart Element
134 
135  OutputFilename(oXml.GetChildString("OutputFilename"));
136 
137  oXml.OutOfElem(); //OutOf FileChart Element
138 }
139 
147 {
148  long lRow, lCol, lIndex;
149 
150  //Add the time columns
151  oStream << "TimeSlice\t" << "Time\t";
152 
153 
154  //Lets go through and save the column names
155  lIndex = m_aryDataColumns.GetSize();
156  for(lCol=0; lCol<lIndex; lCol++)
157  {
158  m_aryDataColumns[lCol]->SaveColumnNames(oStream);
159 
160  if(lCol < (lIndex-1)) oStream << "\t";
161  }
162  oStream << "\n";
163 
164 
165  //Lets go through and dump the buffer
166  long lTimeSlice=0;
167  float fltTime = 0;
168  for(lRow=0; lRow<m_lRowCount; lRow++)
169  {
170  lTimeSlice = m_lStartSlice + (lRow * m_iCollectInterval);
171  fltTime = lTimeSlice * m_lpSim->TimeStep();
172 
173  //Add the time
174  oStream << lTimeSlice << "\t" << fltTime << "\t";
175 
176  for(lCol=0; lCol<m_lColumnCount; lCol++)
177  {
178  lIndex = (lRow*m_lColumnCount) + lCol;
179 
180  oStream << m_aryDataBuffer[lIndex];
181 
182  if(lCol < (m_lColumnCount-1)) oStream << "\t";
183  }
184 
185  oStream << "\n";
186  }
187 
188  oStream.close();
189 
190  //Now get rid of the buffer.
191  if(m_aryDataBuffer) delete[] m_aryDataBuffer;
192  m_aryDataBuffer = NULL;
193 }
194 
195  } //Charting
196 } //AnimatSim
197 
virtual std::string OutputFilename()
Gets the output filename.
Definition: FileChart.cpp:84
Base class file for all Animat simulation objects.
Declares the nervous system class.
Declares the simulation recorder class.
Root namespace for the base simulation library for AnimatLab.
float * m_aryDataBuffer
Buffer for data variable points.
Definition: DataChart.h:66
Declares the body part class.
virtual ~FileChart()
Destructor.
Definition: FileChart.cpp:64
virtual void Initialize()
Initializes this object.
Definition: FileChart.cpp:102
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: FileChart.cpp:121
virtual bool IntoElem()
Goes into the next element where the cursor is located.
Definition: StdXml.cpp:42
FileChart()
Default constructor.
Definition: FileChart.cpp:54
std::string m_strOutputFilename
Filename of the output file.
Definition: FileChart.h:28
virtual void Deactivate()
Deactivates this item.
Definition: FileChart.cpp:111
Declares the key frame class.
virtual void Initialize()
Initializes this object.
Definition: DataChart.cpp:422
Declares the joint class.
Declares the organism class.
Declares a light object.
long m_lColumnCount
Number of data columns.
Definition: DataChart.h:69
Declares the activated item class.
virtual float TimeStep()
Gets the smallest integration time step used within the simulation.
Definition: Simulator.cpp:951
Declares the data column class.
virtual void Load(std::string strProjectPath, std::string strConfigFile)
Loads a data chart from a file.
Definition: DataChart.cpp:867
Declares a light manager object.
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: DataChart.cpp:537
Declares the bounding box class.
Declares the gain base class.
A standard xml manipulation class.
Definition: StdXml.h:19
virtual std::string Type()
returns the string type name of this object.
Definition: FileChart.cpp:74
Declares the node class.
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
Definition: StdXml.cpp:307
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
virtual void SaveOutput()
Saves the data to the specified output file in a tsv format.
Definition: FileChart.cpp:146
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
std::string m_strProjectPath
Full pathname of the project file.
Definition: DataChart.h:35
CStdPtrArray< DataColumn > m_aryDataColumns
The primary array of data columns. This array deletes the columns when destructed.
Definition: DataChart.h:60
Declares the data chart class.
long m_lRowCount
Number of rows in the buffer.
Definition: DataChart.h:72
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
virtual void Deactivate()
Deactivates this item.
Definition: DataChart.cpp:694
Declares the data chart manager class.
Declares the rigid body class.
std::ofstream oStream
The file stream.
Definition: FileChart.h:31
Declares the structure class.
Declares the odor type class.
Declares the file chart class.
Declares the odor class.
Declares the simulator class.
Declares the neural module class.
Declares the activated item manager class.
Declares the contact sensor class.
Declares the external stimuli manager class.
long m_lStartSlice
The time slice where this item becomes active.
Definition: ActivatedItem.h:36
Declares the receptive field class.
short m_iCollectInterval
Tells what the time slice step interval to use when collecting data. This is.
Definition: DataChart.h:44