comparison data/fileio/CSVFileReader.cpp @ 611:dd97f7b3d120

* Add start frame get/set to EditableDenseThreeDimensionalModel and use it when importing grids from CSV with timings attached
author Chris Cannam
date Fri, 11 Sep 2009 15:42:32 +0000
parents 3ccf48fb81d6
children 001db550bd48
comparison
equal deleted inserted replaced
610:0a9e960fca53 611:dd97f7b3d120
97 QString::SplitBehavior behaviour = m_format.getSplitBehaviour(); 97 QString::SplitBehavior behaviour = m_format.getSplitBehaviour();
98 size_t sampleRate = m_format.getSampleRate(); 98 size_t sampleRate = m_format.getSampleRate();
99 size_t windowSize = m_format.getWindowSize(); 99 size_t windowSize = m_format.getWindowSize();
100 100
101 if (timingType == CSVFormat::ExplicitTiming) { 101 if (timingType == CSVFormat::ExplicitTiming) {
102 windowSize = 1; 102 if (modelType == CSVFormat::ThreeDimensionalModel) {
103 // This will be overridden later if more than one line
104 // appears in our file, but we want to choose a default
105 // that's likely to be visible
106 windowSize = 1024;
107 } else {
108 windowSize = 1;
109 }
103 if (timeUnits == CSVFormat::TimeSeconds) { 110 if (timeUnits == CSVFormat::TimeSeconds) {
104 sampleRate = m_mainModelSampleRate; 111 sampleRate = m_mainModelSampleRate;
105 } 112 }
106 } 113 }
107 114
117 unsigned int lineno = 0; 124 unsigned int lineno = 0;
118 125
119 float min = 0.0, max = 0.0; 126 float min = 0.0, max = 0.0;
120 127
121 size_t frameNo = 0; 128 size_t frameNo = 0;
129 size_t startFrame = 0; // for calculation of dense model resolution
122 130
123 while (!in.atEnd()) { 131 while (!in.atEnd()) {
124 132
125 // QTextStream's readLine doesn't cope with old-style Mac 133 // QTextStream's readLine doesn't cope with old-style Mac
126 // CR-only line endings. Why did they bother making the class 134 // CR-only line endings. Why did they bother making the class
243 251
244 for (int i = 0; i < tidyList.size(); ++i) { 252 for (int i = 0; i < tidyList.size(); ++i) {
245 253
246 bool ok = false; 254 bool ok = false;
247 float value = list[i].toFloat(&ok); 255 float value = list[i].toFloat(&ok);
248 values.push_back(value); 256
257 if (i > 0 || timingType != CSVFormat::ExplicitTiming) {
258 values.push_back(value);
259 }
249 260
250 if ((lineno == 0 && i == 0) || value < min) min = value; 261 bool firstEver = (lineno == 0 && i == 0);
251 if ((lineno == 0 && i == 0) || value > max) max = value; 262
263 if (firstEver || value < min) min = value;
264 if (firstEver || value > max) max = value;
265
266 if (firstEver) {
267 startFrame = frameNo;
268 model3->setStartFrame(startFrame);
269 } else if (lineno == 1 &&
270 timingType == CSVFormat::ExplicitTiming) {
271 model3->setResolution(frameNo - startFrame);
272 }
252 273
253 if (!ok) { 274 if (!ok) {
254 if (warnings < warnLimit) { 275 if (warnings < warnLimit) {
255 std::cerr << "WARNING: CSVFileReader::load: " 276 std::cerr << "WARNING: CSVFileReader::load: "
256 << "Non-numeric value \"" 277 << "Non-numeric value \""
266 } 287 }
267 288
268 // std::cerr << "Setting bin values for count " << lineno << ", frame " 289 // std::cerr << "Setting bin values for count " << lineno << ", frame "
269 // << frameNo << ", time " << RealTime::frame2RealTime(frameNo, sampleRate) << std::endl; 290 // << frameNo << ", time " << RealTime::frame2RealTime(frameNo, sampleRate) << std::endl;
270 291
271 model3->setColumn(frameNo / model3->getResolution(), values); 292 model3->setColumn(lineno, values);
272 } 293 }
273 294
274 ++lineno; 295 ++lineno;
275 if (timingType == CSVFormat::ImplicitTiming || 296 if (timingType == CSVFormat::ImplicitTiming ||
276 list.size() == 0) { 297 list.size() == 0) {