[MSCE U13 C++]点云导入和导出添加进度条的问题

老师,您好

       我在导入和导出点云的时候,由于界面长时间出现未响应的状态,需要加入进度条,我参考了论坛上符老师的一个例子,如下:

void completionBarTest()
{
	WString   txtLine;
	int       percent, totLines = 45267;
	MSDialogP cmplDbP = mdlDialog_completionBarOpen(L"Reading ASC DEM DataFile ...");
	mdlDialog_completionBarUpdate(cmplDbP, NULL, 0);
	BeFileStatus status;
	BeTextFilePtr fp = BeTextFile::Open(status, L"D:\\Foo-src\\MDL.V8i\\NorthStar\\catenary\\test\\13.asc", TextFileOpenType::Read, TextFileOptions::KeepNewLine);
	for (int i = 0; i<totLines; i++)
	{
	    fp->GetLine (txtLine);
		percent = i * 100 / totLines;
		if (percent > 100) percent = 100;
		mdlDialog_completionBarUpdate(cmplDbP, NULL, percent);
	}
	mdlDialog_completionBarClose(cmplDbP);
	fp->Close();
}

可以出现进度条对话框,但是进度条并不会更新。后来我发现API文档中自带了点云导入和导出的进度接口IPointCloudImportProgress和IPointCloudPodWriterProgress,但是论坛上找不到相关的资料。请问一下,这两个接口该怎么使用?可以提供一下相关的例子?

Parents Reply
  • 如下代码可以出现进度条,但是每个文件一次进度展示,没有用双进度条。

    ...
    #include <PointCloud\PointCloudApi.h>
    ...
    
    ...
    USING_NAMESPACE_BENTLEY_POINTCLOUD
    ....
    
    MSDialogP g_cmplDbP;
    struct MyPointCloudImportProgress : public IPointCloudImportProgress
    {
    	virtual bool _OnProgress(WCharCP filename, Int32 TotalPercentage, Int32 FilePercentage, ConvertPhase step)
    	{
    		mdlDialog_completionBarUpdate(g_cmplDbP, filename, FilePercentage);
    		return true;
    	}
    	virtual void _OnError(WCharCP message)
    	{
    	}
    };
    void importPointCloud()
    {
    	g_cmplDbP = mdlDialog_completionBarOpen(L"PointCloud Importing ...");
    	mdlDialog_completionBarUpdate(g_cmplDbP, NULL, 0);
    
    	IPointCloudImporterPtr importer = IPointCloudImporter::CreateImporter(L"PointCloud Importer", *ACTIVEMODEL);
    	BeFileListIterator myIter(L"D:\\ValuableQuestions\\0075.LAS-PointCloud", true);
    	BeFileName myName;
    	while (SUCCESS == myIter.GetNextFileName(myName))
    	{
    		importer->AddImportFile(myName.GetName());
    	}
    	MyPointCloudImportProgress progress;
    	importer->SetImportProgress(progress);
    	importer->SetOutputFileName(L"C:\\temp");
    	importer->SetMultipleOutput(true);
    	importer->ConvertToPOD();
    
    	mdlDialog_completionBarClose(g_cmplDbP);
    }



    Answer Verified By: nian chen 

Children
  • 符老师,我现在可以用鼠标选中一块点云导出了,麻烦您可以再测试一下IPointCloudPodWriterProgress接口?我写了一个测试代码,进度条还是不能更新,如果您有时间,麻烦您再帮忙测试一下,谢谢。

    /**************点云另存为pod进度条测试代码*****************/
    bvector<Dpoint3d> rand_point;
    rand_point.resize(1000*10000);
    for (int i = 0; i < 1000 * 10000; ++i)
    {
    	rand_point[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
    	rand_point[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
    	rand_point[i].z = 1024 * rand() / (RAND_MAX + 1.0f);
    }
    StatusInt stat;
    PointCloud::PointCloudPodWriter podW;
    //将点云导出为pod
    UChar ch = 0;
    stat = podW.Initialize(); //Load the dll to write a pod file.
    if (stat != SUCCESS)
    {
    	mdlDialog_dmsgsPrint(L"The pod File initialize was failed!");
    }
    WCharCP filename = L"C:\\mypod.pod";
    stat = podW.StartStream(filename);
    if (stat != SUCCESS)
    {
    	mdlDialog_dmsgsPrint(L"The startstream was completed failed!");
    }
    //podW.SetProgressCallback(myProcessBar);
    PointCloud::PointCloudPodWriter::AddGroup(/*podW.Group_GenNormals | */podW.Group_RescaleIntensities, L"Group");
    stat = podW.AddCloud(/*podW.Cloud_Normal | */podW.Cloud_Intensity, L"myPod", NULL, 0, 0);
    if (stat != SUCCESS)
    {
    	mdlDialog_dmsgsPrint(L"create cloud failed!");
    }
    for (int j = 0; j < 1000 * 10000; ++j)
    {
    	stat = podW.AddPoint(rand_point[j], NULL, 1000, NULL, ch);
    	//myProcessBar._OnProgress(j * 100 / 10000000);
    	//mdlDialog_completionBarUpdate(g_cmplDbP, filename, j * 100 / 10000000);
    }
    stat = podW.EndStream();
    if (stat != SUCCESS)
    {
    	mdlDialog_dmsgsPrint(L"EndStream failed!");
    }
    stat = podW.BuildPod();
    if (stat != SUCCESS)
    {
    	mdlDialog_dmsgsPrint(L"BuildPod failed!");
    }
    //mdlDialog_completionBarClose(g_cmplDbP);

  • 我从你以上代码中没有看到你声明了一个派生于IPointCloudPodWriterProgress的一个类,并在该类中重载_OnProgress函数呀。

    请仔细读懂我给你代码,然后模仿着写就应该可以的。



  • 符老师,不好意思,代码上传的不完整。我试了很多次,还是不成功。

    struct MyPointCloudExportProgress : public IPointCloudPodWriterProgress
    {
    	MyPointCloudExportProgress(WCharCP filename)
    	{
    		m_filename = filename;
    	}
    	//重写
    	virtual void _OnProgress(float progress)
    	{
    		mdlDialog_completionBarUpdate(g_cmplDbP, m_filename, progress);
    	}
    public:
    	WCharCP m_filename;
    };
    
    void ExportPodFile(WCharCP unparsed)
    {
    	/**************点云另存为pod进度条测试代码*****************/
    	bvector<Dpoint3d> rand_point;
    	rand_point.resize(1000*10000);
    	for (int i = 0; i < 1000 * 10000; ++i)
    	{
    		rand_point[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
    		rand_point[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
    		rand_point[i].z = 1024 * rand() / (RAND_MAX + 1.0f);
    	}
    	g_cmplDbP = mdlDialog_completionBarOpen(L"PointCloud Exporting ...");
    	if (NULL == g_cmplDbP)
    	{
    		mdlDialog_dmsgsPrint(L"打开进度条失败!");
    	}
    	mdlDialog_completionBarUpdate(g_cmplDbP, NULL, 0);
    	
    	StatusInt stat;
    	PointCloud::PointCloudPodWriter podW;
    	//将点云导出为pod
    	UChar ch = 0; 
    	stat = podW.Initialize(); //Load the dll to write a pod file.
    	if (stat != SUCCESS)
    	{
    		mdlDialog_dmsgsPrint(L"The pod File initialize was completed failed!");
    	}
    	WCharCP filename = L"C:\\Users\\51267\\Desktop\\mypod.pod";
    	MyPointCloudExportProgress myProcessBar(filename);
    	stat = podW.StartStream(filename);
    	if (stat != SUCCESS)
    	{
    		mdlDialog_dmsgsPrint(L"The startstream was completed failed!");
    	}
    	PointCloud::PointCloudPodWriter::AddGroup(podW.Group_RescaleIntensities, L"Group");
    	stat = podW.AddCloud(podW.Cloud_Intensity, L"myPod", NULL, 0, 0);
    	if (stat != SUCCESS)
    	{
    		mdlDialog_dmsgsPrint(L"create cloud failed!");
    	}
    	podW.SetProgressCallback(myProcessBar);
    	for (int j = 0; j < 1000 * 10000; ++j)
    	{
    		stat = podW.AddPoint(rand_point[j], NULL, 1000, NULL, ch);
    		myProcessBar._OnProgress(j * 100 / 10000000);
    		//mdlDialog_completionBarUpdate(g_cmplDbP, filename, j * 100 / 10000000);
    	}
    	stat = podW.EndStream();
    	if (stat != SUCCESS)
    	{
    		mdlDialog_dmsgsPrint(L"EndStream failed!");
    	}
    	stat = podW.BuildPod();
    	if (stat != SUCCESS)
    	{
    		mdlDialog_dmsgsPrint(L"BuildPod failed!");
    	}
    	mdlDialog_completionBarClose(g_cmplDbP);
    }

  • 如下代码可以,主要是要将传入的进度值乘以100。不过进度条大概显示到35%后就停止了。

    另外请注意,PointCloudPodWriter类下的各函数都是静态函数,故不需要单独声明一个对象后再调用,可直接调用。

    /*--------------------------------------------------------
    | ExportPodFile
    +-------------------------------------------------------*/
    /* Cloud flags */
    #define POD_CloudRetainOrder	1		//!< Indicates cloud point order to be retained
    #define	POD_CloudRowMajor		2		//!< Indicates cloud point order is row first, then columns.
    #define POD_CloudRGB			4		//!< Indicates cloud point RGB color value(s) (Red, Green, Blue)
    #define POD_CloudIntensity		8		//!< Indicates cloud point intensity value
    #define POD_CloudNormal			16		//!< Indicates cloud point surface normal
    #define POD_CloudClassification	32		//!< Indicates cloud points classification
    
    /* Group flags */
    #define POD_GroupCombine			1	//!< Specifies group combine
    #define POD_GroupGenNormals			2	//!< Specifies group generation of surface normals
    #define POD_GroupRescaleIntensities 4	//!< Specifies group rescale of intensity values to optimize contrast
    
    struct MyPointCloudExportProgress : public IPointCloudPodWriterProgress
    {
    	WCharCP m_filename;
    	MyPointCloudExportProgress(WCharCP filename)
    	{
    		m_filename = filename;
    	}
    	virtual void _OnProgress(float progress)
    	{
    		mdlDialog_completionBarUpdate(g_cmplDbP, m_filename, 100*progress);
    	}
    };
    void ExportPodFile(WCharCP filename)
    {
    	bvector<Dpoint3d> rand_point;
    	rand_point.resize(1000 * 10000);
    	for (int i = 0; i < 1000 * 10000; ++i)
    	{
    		rand_point[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
    		rand_point[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
    		rand_point[i].z = 1024 * rand() / (RAND_MAX + 1.0f);
    	}
    	g_cmplDbP = mdlDialog_completionBarOpen(L"PointCloud Exporting ...");
    	mdlDialog_completionBarUpdate(g_cmplDbP, NULL, 0);
    
    	PointCloudPodWriter::Initialize();
    	MyPointCloudExportProgress myProcessBar(filename);
    	PointCloudPodWriter::SetProgressCallback(myProcessBar);
    	StatusInt stat = PointCloudPodWriter::StartStream(filename);
    	if (stat != SUCCESS)
    	{
    		mdlDialog_dmsgsPrint(L"The startstream was completed failed!");
    		return;
    	}
    	PointCloudPodWriter::AddGroup(POD_GroupRescaleIntensities, L"MyGroup");
    	PointCloudPodWriter::AddCloud(POD_CloudIntensity, L"MyCloud", NULL, 0, 0);
    	for (int j = 0; j < 1000 * 10000; ++j)
    	{
    		PointCloudPodWriter::AddPoint(rand_point[j], NULL, 1000, NULL, 0);
    	}
    	PointCloudPodWriter::EndStream();
    	PointCloudPodWriter::BuildPod();
    	mdlDialog_completionBarClose(g_cmplDbP);
    }