而(getline)在VTK程序中未执行
while(getline) is not executing when in VTK program
基本上,我编写了以下代码来尝试获取带有逗号分隔值的testdata文件,以便将各个值放入多维数组中,然后将它们放入VTK的表中(可视化工具包)。 直到我放置大量斜杠的地方,如果我采用该代码(下面没有其余部分,VTK 包含在顶部)。最初的"while(getline(inputData,dataStore))"工作正常,但是当我将其与VTK代码一起放入时,while循环不会执行,有什么想法吗?谢谢。
测试文件('testdata2')如下所示:
2,4,6,8,10,12,14
1,3,5,7,9,11,13
2.3,2.4,2.5,2.6,2.7,2.8,2.9
代码如下所示:
#include <vtkVersion.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderWindow.h>
#include <vtkSmartPointer.h>
#include <vtkChartXY.h>
#include <vtkTable.h>
#include <vtkPlot.h>
#include <vtkFloatArray.h>
#include <vtkContextView.h>
#include <vtkContextScene.h>
#include <vtkPen.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <sstream>
using namespace std;
int main(int, char *[])
{
int number_of_lines = 0;
string dataStore;
string collectedData = "";
char delim = ',';
int commaCount = 0;
string columnData;
char exit;
ifstream inputData;
inputData.open("testdata2");
//if(inputData.is_open()){
while(getline(inputData, dataStore)){
++number_of_lines;
commaCount = count(dataStore.begin(), dataStore.end(), ',');
collectedData += dataStore + "/" ;
}
cout << commaCount << endl;
cout << number_of_lines << endl;
float dataTable[(number_of_lines)][(commaCount+1)];
stringstream iss(collectedData);
string eachrow;
int levelOneCounter = 0;
int levelTwoCOunter = 0;
while(getline(iss, eachrow, '/')){
stringstream innerIss(eachrow);
string eachValue;
while(getline(innerIss, eachValue, ',')){
dataTable[levelOneCounter][levelTwoCOunter] = atof(eachValue.c_str());
levelTwoCOunter++;
}
levelTwoCOunter = 0;
levelOneCounter++;
}
//} ////////////////////////////////////////////////////////////////////////////
// Create a table with some points in it
vtkSmartPointer<vtkTable> table = //initializes a new instance of a VTKTable (using VTKSmartPointer to avoid memory leakage
vtkSmartPointer<vtkTable>::New();
vtkSmartPointer<vtkFloatArray> arrX =
vtkSmartPointer<vtkFloatArray>::New(); //initializes a new instance of a VTKFloatArray to store X values
arrX->SetName("First");
table->AddColumn(arrX); //X array is added to the table
vtkSmartPointer<vtkFloatArray> arrC =
vtkSmartPointer<vtkFloatArray>::New();
arrC->SetName("Second"); //Cosine array is added to the table
table->AddColumn(arrC);
vtkSmartPointer<vtkFloatArray> arrS =
vtkSmartPointer<vtkFloatArray>::New();
arrS->SetName("Third"); //Sine array is added to the table
table->AddColumn(arrS);
//while(getline(inputData, dataStore)){
//++number_of_lines;
//}
// Fill in the table with some example values (part i have to put values i nwith
// int numPoints = number_of_lines; // initialize no. of points
//table->SetNumberOfRows(commaCount+1); // Sets the number of points of the table
table->SetNumberOfRows(7);
for (int j = 0; j <= 6; ++j) // for loop to put in values into table
{
table->SetValue(j, 0, 1);
table->SetValue(j, 1, 2);
table->SetValue(j, 2, 3);
//for(int i = 0; i < number_of_lines; ++i){
//table->SetValue(j, i, dataTable[i][j]);
//}
}
// Set up the view
vtkSmartPointer<vtkContextView> view = //creates view for visualisation to be shown in
vtkSmartPointer<vtkContextView>::New();
view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
// Add multiple line plots, setting the colors etc
vtkSmartPointer<vtkChartXY> chart = //creates new chartXY
vtkSmartPointer<vtkChartXY>::New();
view->GetScene()->AddItem(chart); //access view's scene via GetScene method and add the created chart above
vtkPlot *line = chart->AddPlot(vtkChart::LINE); // Add new vtkPlot to the created chart through addplot method
#if VTK_MAJOR_VERSION <= 5
line->SetInput(table, 0, 1); // puts table into 1st line plot (old versions)
#else
line->SetInputData(table, 0, 1); // puts table into 1st line plot (new versions)
#endif
line->SetColor(0, 255, 0, 255); // colour of 1st line plot
line->SetWidth(1.0); // width of 1st line plot
line = chart->AddPlot(vtkChart::LINE); // add a 2nd line plot
#if VTK_MAJOR_VERSION <= 5
line->SetInput(table, 0, 2);
#else
line->SetInputData(table, 0, 2);
#endif
line->SetColor(255, 0, 0, 255);
line->SetWidth(5.0);
line->GetPen()->SetLineType(2);//For dotted line, can be from 2 to 5 for different dot patterns
//view->GetRenderWindow()->SetMultiSamples(0);
// Start interactor
view->GetInteractor()->Initialize();
view->GetInteractor()->Start();
return EXIT_SUCCESS;
}
尝试替换
getline(iss, eachrow, '/')
跟
std::getline(iss, eachrow, '/')
相关文章:
- 如何在程序执行时查看Valgrind Massif输出(或其他堆分析器)?
- 如何进行程序执行检查
- 捕获异常后如何退出程序执行
- 在程序执行期间从标准输出重定向到自定义流
- 为什么 C++ openMP 程序执行时间更长
- 从Qt应用程序执行MSI文件
- 应用程序执行器 vs lpsz用户名 ADsOpenObject.
- C++:程序执行时"Not Responding"
- JIT 编译器及其在 C++ 前面加快 .NET 中程序执行速度的好处
- 如何让 c++ 程序执行以响应文件打开
- 防止从其他程序执行库中的函数
- Visual样本存储过程从C 程序执行
- 程序执行因细分故障而停止:11
- 注销侏儒会话时如何从Qt应用程序执行"confirm" gnome会话管理器的对话框(不使用QSessionManager)
- 程序执行基本操作所花费的总时间
- 停止直接执行主应用程序并从第二个应用程序执行它
- 引用变量在下一行程序执行后显示未找到的行为
- C 可以在程序执行过程中移动内存映射的文件(boost :: intercecess)移动
- glLinkProgram() 在程序执行中未定义,即使 glew 报告它存在
- 标准 C++ 程序执行期间的函数调用