Tutorial_VisualGeometry.cpp

Tutorial_VisualGeometry.cpp
/*
* Copyright 2015 Autodesk, Inc. All rights reserved.
* Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
* or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
*/
#include "common/basesystemenv.h"
#include "LabEngine/base/kaimlogimplementation.h"
#include "LabEngine/base/kaimfileopener.h"
#include "LabEngine/utils/labengineutils.h"
// This tutorial shows how to recover triangles that represent the NavData loaded in a Database.
//RUN_THIS_FILE
namespace
{
// Use BaseSystemEnv to initialize Kaim::BaseSystem in this tutorial.
// For more information on initializing the BaseSystem, see Tutorial_BaseSystem.cpp.
#define TEST_ENV_CLASS BaseSystemEnv
TEST_ENV {}
// Simple class that shows how to collect an array of Triangles representing a the NavData loaded in a Database.
class NavDataVisualGeometryBuilder : public Kaim::IVisualGeometry
{
public:
virtual void DoBegin(const Kaim::VisualGeometrySetupConfig& /*setupConfig*/) { m_triangles.Clear(); }
virtual void DoPushTriangle(const Kaim::VisualTriangle& triangle) { m_triangles.PushBack(triangle); }
virtual void DoPushLine(const Kaim::VisualLine& /*visualLine*/) {}
virtual void DoPushText(const Kaim::VisualText& /*visualText*/) {}
virtual void DoEnd() {}
KyUInt32 GetTriangleCount() const { return m_triangles.GetCount(); }
private:
};
TUTORIAL // Add NavData with immediate mode (might be slow but convenient).
{
// Create a world and a database.
Kaim::Ptr<Kaim::World> world = *KY_NEW Kaim::World;
Kaim::Database* database = world->GetDatabase(0);
Kaim::Ptr<Kaim::NavData> navData = *KY_NEW Kaim::NavData(database);
Kaim::Ptr<NavDataVisualGeometryBuilder> geometry = *KY_NEW NavDataVisualGeometryBuilder;
database->SetVisualGeometry(geometry);
LabEngine::KaimFileOpener fileOpener; // NOTE: the SDK comes with a default file opener: Kaim::DefaultFileOpener.
if (Kaim::Result::Fail(navData->Load(env.GetAbsoluteInputFileName("GeneratedNavData/plan/plan.NavData").c_str(), &fileOpener)))
return;
navData->Init(database);
navData->AddToDatabaseImmediate(); // To be certain the NavData is added.
// After calling this function (provided the NavData was successfully added),
// geometry should contain all the triangles of the NavData.
database->BuildVisualGeometry();
TestLog() << "There are " << geometry->GetTriangleCount() << " triangles\n";
}
TUTORIAL // Add NavData with async mode (might be slow but convenient).
{
// Create a world and a database.
Kaim::Ptr<Kaim::World> world = *KY_NEW Kaim::World;
Kaim::Database* database = world->GetDatabase(0);
Kaim::Ptr<Kaim::NavData> navData = *KY_NEW Kaim::NavData(database);
Kaim::Ptr<NavDataVisualGeometryBuilder> geometry = *KY_NEW NavDataVisualGeometryBuilder;
database->SetVisualGeometry(geometry);
LabEngine::KaimFileOpener fileOpener; // NOTE: the SDK comes with a default file opener: Kaim::DefaultFileOpener.
if (Kaim::Result::Fail(navData->Load(env.GetAbsoluteInputFileName("GeneratedNavData/plan/plan.NavData").c_str(), &fileOpener)))
return;
navData->Init(database);
navData->AddToDatabaseAsync();
while (database->HasChangedLastFrame() == false) // We need to wait till NavData has loaded.
{
world->Update();
}
// After calling this function (provided the NavData was successfully added),
// geometry should contain all the triangles of the NavData.
database->BuildVisualGeometry();
TestLog() << "There are " << geometry->GetTriangleCount() << " triangles\n";
}
}