<commit_before>/// Game side
#include <LevelLoaderServer.hpp>
#include <EntityComponent/EntityHandler.hpp>
#include <EntityComponent/EntityFactory.hpp>
#include <Doremi/Core/Include/PlayerSpawnerHandler.hpp>
// Components
#include <EntityComponent/Components/TransformComponent.hpp>
#include <EntityComponent/Components/RenderComponent.hpp>
#include <EntityComponent/Components/PotentialFieldComponent.hpp>
#include <EntityComponent/Components/RigidBodyComponent.hpp>
#include <EntityComponent/Components/TriggerComponent.hpp>
#include <EntityComponent/Components/EntitySpawnerComponent.hpp>
/// Engine side
#include <DoremiEngine/Core/Include/SharedContext.hpp>
// Graphic
#include <DoremiEngine/Graphic/Include/GraphicModule.hpp>
#include <DoremiEngine/Graphic/Include/Interface/Manager/SubModuleManager.hpp>
#include <DoremiEngine/Graphic/Include/Interface/Manager/MeshManager.hpp>

// AI
#include <DoremiEngine/AI/Include/AIModule.hpp>
#include <DoremiEngine/AI/Include/Interface/SubModule/PotentialFieldSubModule.hpp>
#include <DoremiEngine/AI/Include/Interface/PotentialField/PotentialFieldActor.hpp>
// Debug?
#include <PotentialFieldGridCreator.hpp>

// Timing
#include <DoremiEngine/Timing/Include/Measurement/TimeMeasurementManager.hpp>

// Physics

/// DEBUG physics TODOJB remove
#include <DoremiEngine/Physics/Include/PhysicsModule.hpp>
#include <DoremiEngine/Physics/Include/PhysicsMaterialManager.hpp>

#include <DoremiEngine/Physics/Include/RigidBodyManager.hpp>

/// Standard
#include <sstream>
#include <fstream>

namespace Doremi
{
    namespace Core
    {
        LevelLoaderServer::LevelLoaderServer(const DoremiEngine::Core::SharedContext& p_sharedContext) : LevelLoader(p_sharedContext) {}

        LevelLoaderServer::~LevelLoaderServer() {}

        void LevelLoaderServer::LoadLevel(const std::string& p_fileName)
        {
            using namespace std;
            string fileName = m_sharedContext.GetWorkingDirectory() + p_fileName;
            ifstream ifs;
            ifs.open(fileName, ifstream::in | ofstream::binary);
            if(ifs.is_open() == true)
            {
                // testa o lsa lite

                // scene name
                int sceneNameSize;
                ifs.read((char*)&sceneNameSize, sizeof(int));
                char* sceneName = new char[sceneNameSize];
                ifs.read((char*)sceneName, sizeof(char) * sceneNameSize);

                // how much different stuff there is
                int nrMats, nrTransforms, nrMeshes, nrLights;
                ifs.read((char*)&nrMats, sizeof(int));
                ifs.read((char*)&nrTransforms, sizeof(int));
                ifs.read((char*)&nrMeshes, sizeof(int));
                ifs.read((char*)&nrLights, sizeof(int));

                LoadMaterial(ifs, nrMats);
                LoadTransforms(ifs, nrTransforms);
                LoadMeshes(ifs, nrMeshes);
                LoadLights(ifs, nrLights);
                BuildEntities();
                LoadTriggers();
            }
            else
            {
                // TODOXX DO something here?
            }
        }

        bool LevelLoaderServer::BuildComponents(int p_entityId, int p_meshCouplingID, std::vector<DoremiEngine::Graphic::Vertex>& p_vertexBuffer)
        {
            bool r_shouldBuildPhysics = true;

            const ObjectCouplingInfo& meshCoupling = m_meshCoupling[p_meshCouplingID];
            // Adds transform components to the world
            EntityHandler::GetInstance().AddComponent(p_entityId, (int)ComponentType::Transform);
            TransformComponent* transComp = EntityHandler::GetInstance().GetComponentFromStorage<TransformComponent>(p_entityId);

            transComp->position = m_transforms[meshCoupling.transformName].translation;
            transComp->rotation = m_transforms[meshCoupling.transformName].rotation;
            transComp->scale = m_transforms[meshCoupling.transformName].scale;

            DoremiEditor::Core::TransformData transformationData = m_transforms[meshCoupling.transformName];

            if(transformationData.attributes.isAIground)
            {
                // Should build a potential field around this mesh
                CreatePotentialfieldAroundMesh(p_vertexBuffer, transformationData);
            }
            else
            {
                // Adds potential field components to the world that is not AI ground
                EntityHandler::GetInstance().AddComponent(p_entityId, (int)ComponentType::PotentialField);
                PotentialFieldComponent* potComp = EntityHandler::GetInstance().GetComponentFromStorage<PotentialFieldComponent>(p_entityId);
                potComp->ChargedActor = m_sharedContext.GetAIModule().GetPotentialFieldSubModule().CreateNewActor(transComp->position, -1, 2, true,
                                                                                DoremiEngine::AI::AIActorType::Wall); // TODOKO hardcoded shiet
            }
            if(transformationData.attributes.isSpawner)
            {
                r_shouldBuildPhysics = false;

                EntityHandler::GetInstance().AddComponent(p_entityId, (int)ComponentType::EntitySpawner);
                EntitySpawnComponent* entitySpawnComp = EntityHandler::GetInstance().GetComponentFromStorage<EntitySpawnComponent>(p_entityId);
                entitySpawnComp->entityBlueprint = Blueprints::EnemyEntity; //(Blueprints)transformationData.attributes.typeBlueprint;
                entitySpawnComp->maxNumSpawnedEntites = transformationData.attributes.spawnMax;
                entitySpawnComp->type = SpawnerType::TimedSpawner;
                entitySpawnComp->timeBetweenSpawns = 10;
                entitySpawnComp->spawnRadius = 100;
            }
            // If spawnpoint
            if(transformationData.attributes.spawnPointID > -1)
            {
                r_shouldBuildPhysics = false;

                // If start point, we also set this as starting respawn
                if(transformationData.attributes.startOrEndPoint == 1)
                {
                    PlayerSpawnerHandler::GetInstance()->SetCurrentSpawner(p_entityId);
                }
                // Add component
                EntityHandler::GetInstance().AddComponent(p_entityId, static_cast<uint32_t>(ComponentType::Trigger));

                // Set spawn point values
                TriggerComponent* t_triggerComp = GetComponent<TriggerComponent>(p_entityId);
                t_triggerComp->triggerType = TriggerType::NewSpawnPointTrigger;

                XMFLOAT3 centerPoint, minPoint, maxPoint;
                // calulate aab
                CalculateAABBBoundingBox(p_vertexBuffer, transformationData, maxPoint, minPoint, centerPoint);

                XMFLOAT3 dimension = XMFLOAT3(abs(minPoint.x - maxPoint.x) / 2.0f, abs(minPoint.y - maxPoint.y) / 2.0f, abs(minPoint.z - maxPoint.z) / 2.0f);

                //// Create material
                int materialTriggID = m_sharedContext.GetPhysicsModule().GetPhysicsMaterialManager().CreateMaterial(0.0f, 0.0f, 0.0f);

                m_sharedContext.GetPhysicsModule().GetRigidBodyManager().AddBoxBodyStatic(p_entityId, centerPoint, XMFLOAT4(0, 0, 0, 1), dimension, materialTriggID);
                m_sharedContext.GetPhysicsModule().GetRigidBodyManager().SetTrigger(p_entityId, true);
            }
            // If endpoint
            if(transformationData.attributes.startOrEndPoint == 2)
            {
                r_shouldBuildPhysics = false;

                // Add component
                EntityHandler::GetInstance().AddComponent(p_entityId, static_cast<uint32_t>(ComponentType::Trigger));

                // Set spawn point values
                TriggerComponent* t_triggerComp = GetComponent<TriggerComponent>(p_entityId);
                t_triggerComp->triggerType = TriggerType::GoalTrigger;

                XMFLOAT3 centerPoint, minPoint, maxPoint;
                // calulate aab
                CalculateAABBBoundingBox(p_vertexBuffer, transformationData, maxPoint, minPoint, centerPoint);

                XMFLOAT3 dimension = XMFLOAT3(abs(minPoint.x - maxPoint.x) / 2.0f, abs(minPoint.y - maxPoint.y) / 2.0f, abs(minPoint.z - maxPoint.z) / 2.0f);

                //// Create material
                int materialTriggID = m_sharedContext.GetPhysicsModule().GetPhysicsMaterialManager().CreateMaterial(0.0f, 0.0f, 0.0f);

                m_sharedContext.GetPhysicsModule().GetRigidBodyManager().AddBoxBodyStatic(p_entityId, centerPoint, XMFLOAT4(0, 0, 0, 1), dimension, materialTriggID);
                m_sharedContext.GetPhysicsModule().GetRigidBodyManager().SetTrigger(p_entityId, true);
            }

            return r_shouldBuildPhysics;
        }

        void LevelLoaderServer::CalculateAABBBoundingBox(const std::vector<DoremiEngine::Graphic::Vertex>& p_vertexBuffer,
                                                         const DoremiEditor::Core::TransformData& p_transformationData, DirectX::XMFLOAT3& o_max,
                                                         DirectX::XMFLOAT3& o_min, DirectX::XMFLOAT3& o_center)
        {
            DirectX::XMFLOAT3 maxPosition =
                DirectX::XMFLOAT3(-100000, -100000, -100000); // Hard coded low maxpos value TODOXX dangerous if maps is outside this scope...
            DirectX::XMFLOAT3 minPosition = DirectX::XMFLOAT3(100000, 100000, 100000);
            size_t length = p_vertexBuffer.size();
            for(size_t i = 0; i < length; i++)
            {
                // Finding max value
                if(p_vertexBuffer[i].position.x > maxPosition.x)
                {
                    maxPosition.x = p_vertexBuffer[i].position.x;
                }
                if(p_vertexBuffer[i].position.y > maxPosition.y)
                {
                    maxPosition.y = p_vertexBuffer[i].position.y;
                }
                if(p_vertexBuffer[i].position.z > maxPosition.z)
                {
                    maxPosition.z = p_vertexBuffer[i].position.z;
                }

                // FInding min value
                if(p_vertexBuffer[i].position.x < minPosition.x)
                {
                    minPosition.x = p_vertexBuffer[i].position.x;
                }
                if(p_vertexBuffer[i].position.y < minPosition.y)
                {
                    minPosition.y = p_vertexBuffer[i].position.y;
                }
                if(p_vertexBuffer[i].position.z < minPosition.z)
                {
                    minPosition.z = p_vertexBuffer[i].position.z;
                }
            }
            // Max and min are now centered around origo with no scale and no rotation...
            DirectX::XMVECTOR maxVector = XMLoadFloat3(&maxPosition);
            DirectX::XMVECTOR minVector = XMLoadFloat3(&minPosition);
            DirectX::XMMATRIX rotation = XMMatrixRotationQuaternion(XMLoadFloat4(&p_transformationData.rotation));
            DirectX::XMMATRIX translation = XMMatrixTranslationFromVector(XMLoadFloat3(&p_transformationData.translation));
            DirectX::XMMATRIX scale = XMMatrixScalingFromVector(XMLoadFloat3(&p_transformationData.scale));
            maxVector = XMVector3Transform(maxVector, scale);
            maxVector = XMVector3Transform(maxVector, translation);

            minVector = XMVector3Transform(minVector, scale);
            minVector = XMVector3Transform(minVector, translation);
            // minVector = XMVector3Transform(minVector, translation * rotation * scale);
            // maxVector = XMVector3Rotate(maxVector, XMLoadFloat4(&p_transformationData.rotation));
            DirectX::XMFLOAT3 centerPoint;
            XMStoreFloat3(&o_center, (maxVector + minVector) / 2);
            XMStoreFloat3(&o_max, maxVector);
            XMStoreFloat3(&o_min, minVector);
        }

        void LevelLoaderServer::CreatePotentialfieldAroundMesh(const std::vector<DoremiEngine::Graphic::Vertex>& p_vertexBuffer,
                                                               const DoremiEditor::Core::TransformData& p_transformationData)
        {
            using namespace DirectX;
            XMFLOAT3 centerPoint, minPoint, maxPoint;
            CalculateAABBBoundingBox(p_vertexBuffer, p_transformationData, maxPoint, minPoint, centerPoint);

            centerPoint.y = maxPoint.y;
            PotentialFieldGridCreator t_gridCreator = PotentialFieldGridCreator(m_sharedContext);
            DoremiEngine::AI::PotentialField* field =
                m_sharedContext.GetAIModule().GetPotentialFieldSubModule().CreateNewField(maxPoint.x - minPoint.x, maxPoint.z - minPoint.z, 1, 1, centerPoint);
            t_gridCreator.BuildGridUsingPhysicXAndGrid(field);
        }
    }
}
<commit_msg>Added elevator load code from levelloader<commit_after>/// Game side
#include <LevelLoaderServer.hpp>
#include <EntityComponent/EntityHandler.hpp>
#include <EntityComponent/EntityFactory.hpp>
#include <Doremi/Core/Include/PlayerSpawnerHandler.hpp>
// Components
#include <EntityComponent/Components/TransformComponent.hpp>
#include <EntityComponent/Components/RenderComponent.hpp>
#include <EntityComponent/Components/PotentialFieldComponent.hpp>
#include <EntityComponent/Components/RigidBodyComponent.hpp>
#include <EntityComponent/Components/TriggerComponent.hpp>
#include <EntityComponent/Components/EntitySpawnerComponent.hpp>
#include <EntityComponent/Components/PlatformPatrolComponent.hpp>

/// Engine side
#include <DoremiEngine/Core/Include/SharedContext.hpp>
// Graphic
#include <DoremiEngine/Graphic/Include/GraphicModule.hpp>
#include <DoremiEngine/Graphic/Include/Interface/Manager/SubModuleManager.hpp>
#include <DoremiEngine/Graphic/Include/Interface/Manager/MeshManager.hpp>

// AI
#include <DoremiEngine/AI/Include/AIModule.hpp>
#include <DoremiEngine/AI/Include/Interface/SubModule/PotentialFieldSubModule.hpp>
#include <DoremiEngine/AI/Include/Interface/PotentialField/PotentialFieldActor.hpp>
// Debug?
#include <PotentialFieldGridCreator.hpp>

// Timing
#include <DoremiEngine/Timing/Include/Measurement/TimeMeasurementManager.hpp>

// Physics

/// DEBUG physics TODOJB remove
#include <DoremiEngine/Physics/Include/PhysicsModule.hpp>
#include <DoremiEngine/Physics/Include/PhysicsMaterialManager.hpp>

#include <DoremiEngine/Physics/Include/RigidBodyManager.hpp>

/// Standard
#include <sstream>
#include <fstream>

namespace Doremi
{
    namespace Core
    {
        LevelLoaderServer::LevelLoaderServer(const DoremiEngine::Core::SharedContext& p_sharedContext) : LevelLoader(p_sharedContext) {}

        LevelLoaderServer::~LevelLoaderServer() {}

        void LevelLoaderServer::LoadLevel(const std::string& p_fileName)
        {
            using namespace std;
            string fileName = m_sharedContext.GetWorkingDirectory() + p_fileName;
            ifstream ifs;
            ifs.open(fileName, ifstream::in | ofstream::binary);
            if(ifs.is_open() == true)
            {
                // testa o lsa lite

                // scene name
                int sceneNameSize;
                ifs.read((char*)&sceneNameSize, sizeof(int));
                char* sceneName = new char[sceneNameSize];
                ifs.read((char*)sceneName, sizeof(char) * sceneNameSize);

                // how much different stuff there is
                int nrMats, nrTransforms, nrMeshes, nrLights;
                ifs.read((char*)&nrMats, sizeof(int));
                ifs.read((char*)&nrTransforms, sizeof(int));
                ifs.read((char*)&nrMeshes, sizeof(int));
                ifs.read((char*)&nrLights, sizeof(int));

                LoadMaterial(ifs, nrMats);
                LoadTransforms(ifs, nrTransforms);
                LoadMeshes(ifs, nrMeshes);
                LoadLights(ifs, nrLights);
                BuildEntities();
                LoadTriggers();
            }
            else
            {
                // TODOXX DO something here?
            }
        }

        bool LevelLoaderServer::BuildComponents(int p_entityId, int p_meshCouplingID, std::vector<DoremiEngine::Graphic::Vertex>& p_vertexBuffer)
        {
            bool r_shouldBuildPhysics = true;

            const ObjectCouplingInfo& meshCoupling = m_meshCoupling[p_meshCouplingID];
            // Adds transform components to the world
            EntityHandler::GetInstance().AddComponent(p_entityId, (int)ComponentType::Transform);
            TransformComponent* transComp = EntityHandler::GetInstance().GetComponentFromStorage<TransformComponent>(p_entityId);

            transComp->position = m_transforms[meshCoupling.transformName].translation;
            transComp->rotation = m_transforms[meshCoupling.transformName].rotation;
            transComp->scale = m_transforms[meshCoupling.transformName].scale;

            DoremiEditor::Core::TransformData transformationData = m_transforms[meshCoupling.transformName];

            if(transformationData.attributes.isAIground)
            {
                // Should build a potential field around this mesh
                CreatePotentialfieldAroundMesh(p_vertexBuffer, transformationData);
            }
            else
            {
                // Adds potential field components to the world that is not AI ground
                EntityHandler::GetInstance().AddComponent(p_entityId, (int)ComponentType::PotentialField);
                PotentialFieldComponent* potComp = EntityHandler::GetInstance().GetComponentFromStorage<PotentialFieldComponent>(p_entityId);
                potComp->ChargedActor = m_sharedContext.GetAIModule().GetPotentialFieldSubModule().CreateNewActor(transComp->position, -1, 2, true,
                                                                                DoremiEngine::AI::AIActorType::Wall); // TODOKO hardcoded shiet
            }
            if(transformationData.attributes.isSpawner)
            {
                r_shouldBuildPhysics = false;

                EntityHandler::GetInstance().AddComponent(p_entityId, (int)ComponentType::EntitySpawner);
                EntitySpawnComponent* entitySpawnComp = EntityHandler::GetInstance().GetComponentFromStorage<EntitySpawnComponent>(p_entityId);
                entitySpawnComp->entityBlueprint = Blueprints::EnemyEntity; //(Blueprints)transformationData.attributes.typeBlueprint;
                entitySpawnComp->maxNumSpawnedEntites = transformationData.attributes.spawnMax;
                entitySpawnComp->type = SpawnerType::TimedSpawner;
                entitySpawnComp->timeBetweenSpawns = 10;
                entitySpawnComp->spawnRadius = 100;
            }
            // If spawnpoint
            if(transformationData.attributes.spawnPointID > -1)
            {
                r_shouldBuildPhysics = false;

                // If start point, we also set this as starting respawn
                if(transformationData.attributes.startOrEndPoint == 1)
                {
                    PlayerSpawnerHandler::GetInstance()->SetCurrentSpawner(p_entityId);
                }
                // Add component
                EntityHandler::GetInstance().AddComponent(p_entityId, static_cast<uint32_t>(ComponentType::Trigger));

                // Set spawn point values
                TriggerComponent* t_triggerComp = GetComponent<TriggerComponent>(p_entityId);
                t_triggerComp->triggerType = TriggerType::NewSpawnPointTrigger;

                XMFLOAT3 centerPoint, minPoint, maxPoint;
                // calulate aab
                CalculateAABBBoundingBox(p_vertexBuffer, transformationData, maxPoint, minPoint, centerPoint);

                XMFLOAT3 dimension = XMFLOAT3(abs(minPoint.x - maxPoint.x) / 2.0f, abs(minPoint.y - maxPoint.y) / 2.0f, abs(minPoint.z - maxPoint.z) / 2.0f);

                //// Create material
                int materialTriggID = m_sharedContext.GetPhysicsModule().GetPhysicsMaterialManager().CreateMaterial(0.0f, 0.0f, 0.0f);

                m_sharedContext.GetPhysicsModule().GetRigidBodyManager().AddBoxBodyStatic(p_entityId, centerPoint, XMFLOAT4(0, 0, 0, 1), dimension, materialTriggID);
                m_sharedContext.GetPhysicsModule().GetRigidBodyManager().SetTrigger(p_entityId, true);
            }
            // If endpoint
            if(transformationData.attributes.startOrEndPoint == 2)
            {
                r_shouldBuildPhysics = false;

                // Add component
                EntityHandler::GetInstance().AddComponent(p_entityId, static_cast<uint32_t>(ComponentType::Trigger));

                // Set spawn point values
                TriggerComponent* t_triggerComp = GetComponent<TriggerComponent>(p_entityId);
                t_triggerComp->triggerType = TriggerType::GoalTrigger;

                XMFLOAT3 centerPoint, minPoint, maxPoint;
                // calulate aab
                CalculateAABBBoundingBox(p_vertexBuffer, transformationData, maxPoint, minPoint, centerPoint);

                XMFLOAT3 dimension = XMFLOAT3(abs(minPoint.x - maxPoint.x) / 2.0f, abs(minPoint.y - maxPoint.y) / 2.0f, abs(minPoint.z - maxPoint.z) / 2.0f);

                //// Create material
                int materialTriggID = m_sharedContext.GetPhysicsModule().GetPhysicsMaterialManager().CreateMaterial(0.0f, 0.0f, 0.0f);

                m_sharedContext.GetPhysicsModule().GetRigidBodyManager().AddBoxBodyStatic(p_entityId, centerPoint, XMFLOAT4(0, 0, 0, 1), dimension, materialTriggID);
                m_sharedContext.GetPhysicsModule().GetRigidBodyManager().SetTrigger(p_entityId, true);
            }
            if(transformationData.attributes.frequencyAffected)
            {
                // Add component
                EntityHandler::GetInstance().AddComponent(p_entityId, static_cast<uint32_t>(ComponentType::FrequencyAffected));

                PlatformPatrolComponent* platComp = GetComponent<PlatformPatrolComponent>(p_entityId);
                platComp->startPosition = transformationData.attributes.interactableStartPos;
                platComp->endPosition = transformationData.attributes.interactableEndPos;
            }

            return r_shouldBuildPhysics;
        }

        void LevelLoaderServer::CalculateAABBBoundingBox(const std::vector<DoremiEngine::Graphic::Vertex>& p_vertexBuffer,
                                                         const DoremiEditor::Core::TransformData& p_transformationData, DirectX::XMFLOAT3& o_max,
                                                         DirectX::XMFLOAT3& o_min, DirectX::XMFLOAT3& o_center)
        {
            DirectX::XMFLOAT3 maxPosition =
                DirectX::XMFLOAT3(-100000, -100000, -100000); // Hard coded low maxpos value TODOXX dangerous if maps is outside this scope...
            DirectX::XMFLOAT3 minPosition = DirectX::XMFLOAT3(100000, 100000, 100000);
            size_t length = p_vertexBuffer.size();
            for(size_t i = 0; i < length; i++)
            {
                // Finding max value
                if(p_vertexBuffer[i].position.x > maxPosition.x)
                {
                    maxPosition.x = p_vertexBuffer[i].position.x;
                }
                if(p_vertexBuffer[i].position.y > maxPosition.y)
                {
                    maxPosition.y = p_vertexBuffer[i].position.y;
                }
                if(p_vertexBuffer[i].position.z > maxPosition.z)
                {
                    maxPosition.z = p_vertexBuffer[i].position.z;
                }

                // FInding min value
                if(p_vertexBuffer[i].position.x < minPosition.x)
                {
                    minPosition.x = p_vertexBuffer[i].position.x;
                }
                if(p_vertexBuffer[i].position.y < minPosition.y)
                {
                    minPosition.y = p_vertexBuffer[i].position.y;
                }
                if(p_vertexBuffer[i].position.z < minPosition.z)
                {
                    minPosition.z = p_vertexBuffer[i].position.z;
                }
            }
            // Max and min are now centered around origo with no scale and no rotation...
            DirectX::XMVECTOR maxVector = XMLoadFloat3(&maxPosition);
            DirectX::XMVECTOR minVector = XMLoadFloat3(&minPosition);
            DirectX::XMMATRIX rotation = XMMatrixRotationQuaternion(XMLoadFloat4(&p_transformationData.rotation));
            DirectX::XMMATRIX translation = XMMatrixTranslationFromVector(XMLoadFloat3(&p_transformationData.translation));
            DirectX::XMMATRIX scale = XMMatrixScalingFromVector(XMLoadFloat3(&p_transformationData.scale));
            maxVector = XMVector3Transform(maxVector, scale);
            maxVector = XMVector3Transform(maxVector, translation);

            minVector = XMVector3Transform(minVector, scale);
            minVector = XMVector3Transform(minVector, translation);
            // minVector = XMVector3Transform(minVector, translation * rotation * scale);
            // maxVector = XMVector3Rotate(maxVector, XMLoadFloat4(&p_transformationData.rotation));
            DirectX::XMFLOAT3 centerPoint;
            XMStoreFloat3(&o_center, (maxVector + minVector) / 2);
            XMStoreFloat3(&o_max, maxVector);
            XMStoreFloat3(&o_min, minVector);
        }

        void LevelLoaderServer::CreatePotentialfieldAroundMesh(const std::vector<DoremiEngine::Graphic::Vertex>& p_vertexBuffer,
                                                               const DoremiEditor::Core::TransformData& p_transformationData)
        {
            using namespace DirectX;
            XMFLOAT3 centerPoint, minPoint, maxPoint;
            CalculateAABBBoundingBox(p_vertexBuffer, p_transformationData, maxPoint, minPoint, centerPoint);

            centerPoint.y = maxPoint.y;
            PotentialFieldGridCreator t_gridCreator = PotentialFieldGridCreator(m_sharedContext);
            DoremiEngine::AI::PotentialField* field =
                m_sharedContext.GetAIModule().GetPotentialFieldSubModule().CreateNewField(maxPoint.x - minPoint.x, maxPoint.z - minPoint.z, 1, 1, centerPoint);
            t_gridCreator.BuildGridUsingPhysicXAndGrid(field);
        }
    }
}
<|endoftext|>


<commit_before><commit_msg>`app::delete_entity`: added `const` modifier to a variable.<commit_after><|endoftext|>


<commit_before>#include "astutil.h"
#include "expr.h"
#include "optimizations.h"
#include "passes.h"
#include "stmt.h"
#include "stringutil.h"
#include "symbol.h"
#include "type.h"

static Type* getWrapRecordBaseType(Type* type);

//
// removes _array and _domain wrapper records
//
void
removeWrapRecords() {
  //
  // do not remove wrap records if dead code elimination is disabled
  // (or weakened because inlining or copy propagation is disabled)
  // because code associated with accesses to the removed
  // _valueType field will remain
  //
  if (fNoDeadCodeElimination || fNoInline || fNoCopyPropagation)
    return;

  //
  // replace use of _valueType field with type
  //
  forv_Vec(CallExpr, call, gCallExprs) {
    if (call->isPrimitive(PRIMITIVE_PRIVATE_GET_CLASS)) {
      call->get(1)->replace(new SymExpr(call->get(1)->typeInfo()->symbol));
    }
  }

  //
  // remove defs of _valueType field
  //
  forv_Vec(CallExpr, call, gCallExprs) {
    if (call->isPrimitive(PRIMITIVE_SET_MEMBER) ||
        call->isPrimitive(PRIMITIVE_GET_MEMBER) ||
        call->isPrimitive(PRIMITIVE_GET_MEMBER_VALUE)) {
      if (SymExpr* se = toSymExpr(call->get(2))) {
        if (!strcmp(se->var->name, "_valueType")) {
          se->getStmtExpr()->remove();
        }
      }
    }
  }

  //
  // remove _valueType fields
  //
  forv_Vec(ClassType, ct, gClassTypes) {
    for_fields(field, ct) {
      if (!strcmp(field->name, "_valueType"))
        field->defPoint->remove();
    }
  }

  //
  // remove formals for _valueType fields in constructors
  //
  compute_call_sites();
  forv_Vec(FnSymbol, fn, gFnSymbols) {
    for_formals(formal, fn) {
      if (!strcmp(formal->name, "_valueType")) {
        forv_Vec(CallExpr, call, *fn->calledBy) {
          formal_to_actual(call, formal)->remove();
        }
        formal->defPoint->remove();
      }
    }
  }

  //
  // replace accesses of _value with wrap record
  //
  forv_Vec(CallExpr, call, gCallExprs) {
    if (call->isPrimitive(PRIMITIVE_SET_MEMBER)) {
      if (SymExpr* se = toSymExpr(call->get(1))) {
        if (se->var->type->symbol->hasFlag(FLAG_ARRAY) ||
            se->var->type->symbol->hasFlag(FLAG_DOMAIN)) {
          call->primitive = primitives[PRIMITIVE_MOVE];
          call->get(2)->remove();
        }
      }
    } else if (call->isPrimitive(PRIMITIVE_GET_MEMBER)) {
      if (SymExpr* se = toSymExpr(call->get(1))) {
        if (se->var->type->symbol->hasFlag(FLAG_ARRAY) ||
            se->var->type->symbol->hasFlag(FLAG_DOMAIN)) {
          call->primitive = primitives[PRIMITIVE_SET_REF];
          call->get(2)->remove();
        }
      }
    } else if (call->isPrimitive(PRIMITIVE_GET_MEMBER_VALUE)) {
      if (SymExpr* se = toSymExpr(call->get(1))) {
        if (se->var->type->symbol->hasFlag(FLAG_ARRAY) ||
            se->var->type->symbol->hasFlag(FLAG_DOMAIN)) {
          call->replace(se->remove());
        }
      }
    }
  }

  //
  // scalar replace wrap records
  //
  forv_Vec(VarSymbol, var, gVarSymbols) {
    if (Type* type = getWrapRecordBaseType(var->type))
      if (!var->defPoint->parentSymbol->hasFlag(FLAG_REF)) // refs second
        var->type = type;
  }
  forv_Vec(ArgSymbol, arg, gArgSymbols) {
    if (Type* type = getWrapRecordBaseType(arg->type)) {
      arg->intent = INTENT_BLANK; // see test/arrays/deitz/test_out_array
      arg->type = type;
    }
  }
  forv_Vec(FnSymbol, fn, gFnSymbols) {
    if (Type* type = getWrapRecordBaseType(fn->retType))
      fn->retType = type;
  }
  forv_Vec(ClassType, ct, gClassTypes) {
    if (ct->symbol->hasFlag(FLAG_REF))
      if (Symbol* var = ct->getField(1))
        if (Type* type = getWrapRecordBaseType(var->type))
          var->type = type;
  }

  //
  // fix array element type for arrays of arrays and arrays of domains
  //
  forv_Vec(ClassType, ct, gClassTypes) {
    if (ct->symbol->hasFlag(FLAG_DATA_CLASS)) {
      if (TypeSymbol* ts = toTypeSymbol(ct->substitutions.v[0].value)) {
        if (ts->hasFlag(FLAG_ARRAY) || ts->hasFlag(FLAG_DOMAIN)) {
          ct->substitutions.v[0].value = ts->type->getField("_value")->type->symbol;
        }
      }
    }
  }
}

static Type*
getWrapRecordBaseType(Type* type) {
  if (type->symbol->hasFlag(FLAG_ARRAY) ||
      type->symbol->hasFlag(FLAG_DOMAIN)) {
    return type->getField("_value")->type;
  } else if (type->symbol->hasFlag(FLAG_REF)) {
    Type* vt = type->getValueType();
    if (vt->symbol->hasFlag(FLAG_ARRAY) ||
        vt->symbol->hasFlag(FLAG_DOMAIN)) {
      return vt->getField("_value")->type->refType;
    }
  }
  return NULL;
}
<commit_msg>Fixed a bug in removeWrapRecords in which reference types to wrap records were modified to reference the wrapped value.  Since these references are never used, this wasn't a serious issue, but the variant of prune executed with --destroy-value-type-vars ran into some serious problems.<commit_after>#include "astutil.h"
#include "expr.h"
#include "optimizations.h"
#include "passes.h"
#include "stmt.h"
#include "stringutil.h"
#include "symbol.h"
#include "type.h"

static Type* getWrapRecordBaseType(Type* type);

//
// removes _array and _domain wrapper records
//
void
removeWrapRecords() {
  //
  // do not remove wrap records if dead code elimination is disabled
  // (or weakened because inlining or copy propagation is disabled)
  // because code associated with accesses to the removed
  // _valueType field will remain
  //
  if (fNoDeadCodeElimination || fNoInline || fNoCopyPropagation)
    return;

  //
  // replace use of _valueType field with type
  //
  forv_Vec(CallExpr, call, gCallExprs) {
    if (call->isPrimitive(PRIMITIVE_PRIVATE_GET_CLASS)) {
      call->get(1)->replace(new SymExpr(call->get(1)->typeInfo()->symbol));
    }
  }

  //
  // remove defs of _valueType field
  //
  forv_Vec(CallExpr, call, gCallExprs) {
    if (call->isPrimitive(PRIMITIVE_SET_MEMBER) ||
        call->isPrimitive(PRIMITIVE_GET_MEMBER) ||
        call->isPrimitive(PRIMITIVE_GET_MEMBER_VALUE)) {
      if (SymExpr* se = toSymExpr(call->get(2))) {
        if (!strcmp(se->var->name, "_valueType")) {
          se->getStmtExpr()->remove();
        }
      }
    }
  }

  //
  // remove _valueType fields
  //
  forv_Vec(ClassType, ct, gClassTypes) {
    for_fields(field, ct) {
      if (!strcmp(field->name, "_valueType"))
        field->defPoint->remove();
    }
  }

  //
  // remove formals for _valueType fields in constructors
  //
  compute_call_sites();
  forv_Vec(FnSymbol, fn, gFnSymbols) {
    for_formals(formal, fn) {
      if (!strcmp(formal->name, "_valueType")) {
        forv_Vec(CallExpr, call, *fn->calledBy) {
          formal_to_actual(call, formal)->remove();
        }
        formal->defPoint->remove();
      }
    }
  }

  //
  // replace accesses of _value with wrap record
  //
  forv_Vec(CallExpr, call, gCallExprs) {
    if (call->isPrimitive(PRIMITIVE_SET_MEMBER)) {
      if (SymExpr* se = toSymExpr(call->get(1))) {
        if (se->var->type->symbol->hasFlag(FLAG_ARRAY) ||
            se->var->type->symbol->hasFlag(FLAG_DOMAIN)) {
          call->primitive = primitives[PRIMITIVE_MOVE];
          call->get(2)->remove();
        }
      }
    } else if (call->isPrimitive(PRIMITIVE_GET_MEMBER)) {
      if (SymExpr* se = toSymExpr(call->get(1))) {
        if (se->var->type->symbol->hasFlag(FLAG_ARRAY) ||
            se->var->type->symbol->hasFlag(FLAG_DOMAIN)) {
          call->primitive = primitives[PRIMITIVE_SET_REF];
          call->get(2)->remove();
        }
      }
    } else if (call->isPrimitive(PRIMITIVE_GET_MEMBER_VALUE)) {
      if (SymExpr* se = toSymExpr(call->get(1))) {
        if (se->var->type->symbol->hasFlag(FLAG_ARRAY) ||
            se->var->type->symbol->hasFlag(FLAG_DOMAIN)) {
          call->replace(se->remove());
        }
      }
    }
  }

  //
  // scalar replace wrap records
  //
  forv_Vec(VarSymbol, var, gVarSymbols) {
    if (Type* type = getWrapRecordBaseType(var->type))
      if (!var->defPoint->parentSymbol->hasFlag(FLAG_REF))
        var->type = type;
  }
  forv_Vec(ArgSymbol, arg, gArgSymbols) {
    if (Type* type = getWrapRecordBaseType(arg->type)) {
      arg->intent = INTENT_BLANK; // see test/arrays/deitz/test_out_array
      arg->type = type;
    }
  }
  forv_Vec(FnSymbol, fn, gFnSymbols) {
    if (Type* type = getWrapRecordBaseType(fn->retType))
      fn->retType = type;
  }

  //
  // fix array element type for arrays of arrays and arrays of domains
  //
  forv_Vec(ClassType, ct, gClassTypes) {
    if (ct->symbol->hasFlag(FLAG_DATA_CLASS)) {
      if (TypeSymbol* ts = toTypeSymbol(ct->substitutions.v[0].value)) {
        if (ts->hasFlag(FLAG_ARRAY) || ts->hasFlag(FLAG_DOMAIN)) {
          ct->substitutions.v[0].value = ts->type->getField("_value")->type->symbol;
        }
      }
    }
  }
}

static Type*
getWrapRecordBaseType(Type* type) {
  if (type->symbol->hasFlag(FLAG_ARRAY) ||
      type->symbol->hasFlag(FLAG_DOMAIN)) {
    return type->getField("_value")->type;
  } else if (type->symbol->hasFlag(FLAG_REF)) {
    Type* vt = type->getValueType();
    if (vt->symbol->hasFlag(FLAG_ARRAY) ||
        vt->symbol->hasFlag(FLAG_DOMAIN)) {
      return vt->getField("_value")->type->refType;
    }
  }
  return NULL;
}
<|endoftext|>


<commit_before>/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.

  Some parts of this code are derived from ITK. See ITKCopyright.txt
  for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#ifdef __BORLANDC__
#define ITK_LEAN_AND_MEAN
#endif

// Software Guide : BeginLatex
//
// Here we are illustrating the use of the
// \doxygen{otb}{SimpleRcsPanSharpeningFusionImageFilter} for PAN-sharpening.
// This example takes a PAN and the corresponding XS images as input. These
// images are supposed to be registered.
//
// The fusion operation is defined as
//
// \begin{equation}
// \frac{XS}{\mathrm{Filtered}(PAN)} PAN
// \end{equation}
//
// Software Guide : EndLatex

//  Software Guide : BeginCommandLineArgs
//    INPUTS: {QB_Toulouse_Ortho_PAN.tif QB_Toulouse_Ortho_XS.tif}
//    OUTPUTS: {QB_Toulouse_Ortho_PXS.tif pretty_QB_Toulouse_Ortho_PXS.png
//       pretty_QB_Toulouse_Ortho_PAN.png pretty_QB_Toulouse_Ortho_XS.png}
//  Software Guide : EndCommandLineArgs

// Software Guide : BeginLatex
//
// We start by including the required header and declaring the main function:
//
// Software Guide : EndLatex

// Software Guide : BeginCodeSnippet
#include "otbImage.h"
#include "otbVectorImage.h"
#include "otbImageFileReader.h"
#include "otbStreamingImageFileWriter.h"
#include "otbSimpleRcsPanSharpeningFusionImageFilter.h"
// Software Guide : EndCodeSnippet

#include "otbPrintableImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"

// Software Guide : BeginCodeSnippet
int main( int argc, char* argv[] )
{
// Software Guide : EndCodeSnippet

  if( argc < 4 )
  {
    std::cerr << "Missing Parameters " << std::endl;
    std::cerr << "Usage: " << argv[0];
    std::cerr << " inputPanchromatiqueImage inputMultiSpectralImage outputImage outputImagePrinted panchroPrinted msPrinted" << std::endl;
    return 1;
  }

  // Software Guide : BeginLatex
  //
  // We declare the different image type used here as well as the image reader.
  // Note that, the reader for the PAN image is templated by an
  // \doxygen{otb}{Image} while the XS reader uses an
  // \doxygen{otb}{VectorImage}.
  //
  // Software Guide : EndLatex

  // Software Guide : BeginCodeSnippet
  typedef otb::Image<double, 2>     ImageType;
  typedef otb::VectorImage<double, 2>     VectorImageType;
  typedef otb::ImageFileReader<ImageType>  ReaderType;
  typedef otb::ImageFileReader<VectorImageType>  ReaderVectorType;
  typedef otb::VectorImage<unsigned int, 2>     VectorIntImageType;

  ReaderVectorType::Pointer     	readerXS=ReaderVectorType::New();
  ReaderType::Pointer     	readerPAN=ReaderType::New();
  // Software Guide : EndCodeSnippet

  // Software Guide : BeginLatex
  //
  // We pass the filenames to the readers
  //
  // Software Guide : EndLatex

  // Software Guide : BeginCodeSnippet
  readerPAN->SetFileName(argv[1]);
  readerXS->SetFileName(argv[2]);
  // Software Guide : EndCodeSnippet

  // Software Guide : BeginLatex
  //
  // We declare the fusion filter an set its inputs using the readers:
  //
  // Software Guide : EndLatex

  // Software Guide : BeginCodeSnippet
  typedef otb::SimpleRcsPanSharpeningFusionImageFilter
      <ImageType,VectorImageType,VectorIntImageType> FusionFilterType;
  FusionFilterType::Pointer fusion = FusionFilterType::New();
  fusion->SetPanInput(readerPAN->GetOutput());
  fusion->SetXsInput(readerXS->GetOutput());
  // Software Guide : EndCodeSnippet

  // Software Guide : BeginLatex
  //
  // And finally, we declare the writer and call its \code{Update()} method to
  // trigger the full pipeline execution.
  //
  // Software Guide : EndLatex

  // Software Guide : BeginCodeSnippet
  typedef otb::StreamingImageFileWriter<VectorIntImageType>  WriterType;
  WriterType::Pointer	    	writer=WriterType::New();
  writer->SetFileName(argv[3]);
  writer->SetInput(fusion->GetOutput());
  writer->Update();
  // Software Guide : EndCodeSnippet

  typedef otb::PrintableImageFilter<VectorIntImageType> PrintableImageType;
  PrintableImageType::Pointer printable = PrintableImageType::New();

  typedef otb::VectorImage<unsigned char, 2>     VectorCharImageType;
  typedef otb::StreamingImageFileWriter<VectorCharImageType>  PNGWriterType;
  PNGWriterType::Pointer pngwriter = PNGWriterType::New();

  printable->SetInput(fusion->GetOutput());
  printable->SetChannel(3);
  printable->SetChannel(2);
  printable->SetChannel(1);
  pngwriter->SetFileName(argv[4]);
  pngwriter->SetInput(printable->GetOutput());
  pngwriter->Update();

  typedef otb::PrintableImageFilter<VectorImageType> PrintableImageType2;
  PrintableImageType2::Pointer printable2 = PrintableImageType2::New();
  printable2->SetInput(readerXS->GetOutput());
  printable2->SetChannel(3);
  printable2->SetChannel(2);
  printable2->SetChannel(1);
  pngwriter->SetFileName(argv[6]);
  pngwriter->SetInput(printable2->GetOutput());
  pngwriter->Update();

  typedef otb::Image<unsigned char, 2>     CharImageType;
  typedef itk::RescaleIntensityImageFilter <ImageType,CharImageType> RescalerType;
  RescalerType::Pointer rescaler = RescalerType::New();
  typedef otb::StreamingImageFileWriter<CharImageType>  PNGWriterType2;
  PNGWriterType2::Pointer pngwriter2 = PNGWriterType2::New();
  rescaler->SetInput(readerPAN->GetOutput());
  pngwriter2->SetFileName(argv[5]);
  pngwriter2->SetInput(rescaler->GetOutput());
  pngwriter2->Update();

// Software Guide : BeginCodeSnippet
  return EXIT_SUCCESS;

}
// Software Guide : EndCodeSnippet

  // Software Guide : BeginLatex
  //
  // Figure~\ref{fig:PANSHARP_FILTER} shows the result of applying
  // this PAN sharpening filter to a Quickbird image.
  // \begin{figure}
  // \center
  // \includegraphics[width=0.44\textwidth]{pretty_QB_Toulouse_Ortho_PAN.eps}
  // \includegraphics[width=0.44\textwidth]{pretty_QB_Toulouse_Ortho_XS.eps}
  // \includegraphics[width=0.44\textwidth]{pretty_QB_Toulouse_Ortho_PXS.eps}
  // \itkcaption[Pan sharpening]{Result of applying
  // the \doxygen{otb}{SimpleRcsPanSharpeningFusionImageFilter} to
  // orthorectified Quickbird
  // image. From left to right : original PAN image, original XS image and the
  // result of the PAN sharpening}
  // \label{fig:PANSHARP_FILTER}
  // \end{figure}
  //
  // Software Guide : EndLatex

<commit_msg>prise en compte des OUTPUTS<commit_after>/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.

  Some parts of this code are derived from ITK. See ITKCopyright.txt
  for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#ifdef __BORLANDC__
#define ITK_LEAN_AND_MEAN
#endif

//  Software Guide : BeginCommandLineArgs
//    INPUTS: {QB_Toulouse_Ortho_PAN.tif}, {QB_Toulouse_Ortho_XS.tif}
//    OUTPUTS: {QB_Toulouse_Ortho_PXS.tif}
//    OUTPUTS: {pretty_QB_Toulouse_Ortho_PXS.png}
//    OUTPUTS: {pretty_QB_Toulouse_Ortho_PAN.png}
//    OUTPUTS: {pretty_QB_Toulouse_Ortho_XS.png}
//  Software Guide : EndCommandLineArgs

// Software Guide : BeginLatex
//
// Here we are illustrating the use of the
// \doxygen{otb}{SimpleRcsPanSharpeningFusionImageFilter} for PAN-sharpening.
// This example takes a PAN and the corresponding XS images as input. These
// images are supposed to be registered.
//
// The fusion operation is defined as
//
// \begin{equation}
// \frac{XS}{\mathrm{Filtered}(PAN)} PAN
// \end{equation}
//
// Software Guide : EndLatex

// Software Guide : BeginLatex
//
// We start by including the required header and declaring the main function:
//
// Software Guide : EndLatex

// Software Guide : BeginCodeSnippet
#include "otbImage.h"
#include "otbVectorImage.h"
#include "otbImageFileReader.h"
#include "otbStreamingImageFileWriter.h"
#include "otbSimpleRcsPanSharpeningFusionImageFilter.h"
// Software Guide : EndCodeSnippet

#include "otbPrintableImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"

// Software Guide : BeginCodeSnippet
int main( int argc, char* argv[] )
{
// Software Guide : EndCodeSnippet

  if( argc < 4 )
  {
    std::cerr << "Missing Parameters " << std::endl;
    std::cerr << "Usage: " << argv[0];
    std::cerr << " inputPanchromatiqueImage inputMultiSpectralImage outputImage outputImagePrinted panchroPrinted msPrinted" << std::endl;
    return 1;
  }

  // Software Guide : BeginLatex
  //
  // We declare the different image type used here as well as the image reader.
  // Note that, the reader for the PAN image is templated by an
  // \doxygen{otb}{Image} while the XS reader uses an
  // \doxygen{otb}{VectorImage}.
  //
  // Software Guide : EndLatex

  // Software Guide : BeginCodeSnippet
  typedef otb::Image<double, 2>     ImageType;
  typedef otb::VectorImage<double, 2>     VectorImageType;
  typedef otb::ImageFileReader<ImageType>  ReaderType;
  typedef otb::ImageFileReader<VectorImageType>  ReaderVectorType;
  typedef otb::VectorImage<unsigned int, 2>     VectorIntImageType;

  ReaderVectorType::Pointer     	readerXS=ReaderVectorType::New();
  ReaderType::Pointer     	readerPAN=ReaderType::New();
  // Software Guide : EndCodeSnippet

  // Software Guide : BeginLatex
  //
  // We pass the filenames to the readers
  //
  // Software Guide : EndLatex

  // Software Guide : BeginCodeSnippet
  readerPAN->SetFileName(argv[1]);
  readerXS->SetFileName(argv[2]);
  // Software Guide : EndCodeSnippet

  // Software Guide : BeginLatex
  //
  // We declare the fusion filter an set its inputs using the readers:
  //
  // Software Guide : EndLatex

  // Software Guide : BeginCodeSnippet
  typedef otb::SimpleRcsPanSharpeningFusionImageFilter
      <ImageType,VectorImageType,VectorIntImageType> FusionFilterType;
  FusionFilterType::Pointer fusion = FusionFilterType::New();
  fusion->SetPanInput(readerPAN->GetOutput());
  fusion->SetXsInput(readerXS->GetOutput());
  // Software Guide : EndCodeSnippet

  // Software Guide : BeginLatex
  //
  // And finally, we declare the writer and call its \code{Update()} method to
  // trigger the full pipeline execution.
  //
  // Software Guide : EndLatex

  // Software Guide : BeginCodeSnippet
  typedef otb::StreamingImageFileWriter<VectorIntImageType>  WriterType;
  WriterType::Pointer	    	writer=WriterType::New();
  writer->SetFileName(argv[3]);
  writer->SetInput(fusion->GetOutput());
  writer->Update();
  // Software Guide : EndCodeSnippet

  typedef otb::PrintableImageFilter<VectorIntImageType> PrintableImageType;
  PrintableImageType::Pointer printable = PrintableImageType::New();

  typedef otb::VectorImage<unsigned char, 2>     VectorCharImageType;
  typedef otb::StreamingImageFileWriter<VectorCharImageType>  PNGWriterType;
  PNGWriterType::Pointer pngwriter = PNGWriterType::New();

  printable->SetInput(fusion->GetOutput());
  printable->SetChannel(3);
  printable->SetChannel(2);
  printable->SetChannel(1);
  pngwriter->SetFileName(argv[4]);
  pngwriter->SetInput(printable->GetOutput());
  pngwriter->Update();

  typedef otb::PrintableImageFilter<VectorImageType> PrintableImageType2;
  PrintableImageType2::Pointer printable2 = PrintableImageType2::New();
  printable2->SetInput(readerXS->GetOutput());
  printable2->SetChannel(3);
  printable2->SetChannel(2);
  printable2->SetChannel(1);
  pngwriter->SetFileName(argv[6]);
  pngwriter->SetInput(printable2->GetOutput());
  pngwriter->Update();

  typedef otb::Image<unsigned char, 2>     CharImageType;
  typedef itk::RescaleIntensityImageFilter <ImageType,CharImageType> RescalerType;
  RescalerType::Pointer rescaler = RescalerType::New();
  typedef otb::StreamingImageFileWriter<CharImageType>  PNGWriterType2;
  PNGWriterType2::Pointer pngwriter2 = PNGWriterType2::New();
  rescaler->SetInput(readerPAN->GetOutput());
  pngwriter2->SetFileName(argv[5]);
  pngwriter2->SetInput(rescaler->GetOutput());
  pngwriter2->Update();

// Software Guide : BeginCodeSnippet
  return EXIT_SUCCESS;

// Software Guide : EndCodeSnippet

  // Software Guide : BeginLatex
  //
  // Figure~\ref{fig:PANSHARP_FILTER} shows the result of applying
  // this PAN sharpening filter to a Quickbird image.
  // \begin{figure}
  // \center
  // \includegraphics[width=0.44\textwidth]{pretty_QB_Toulouse_Ortho_PAN.eps}
  // \includegraphics[width=0.44\textwidth]{pretty_QB_Toulouse_Ortho_XS.eps}
  // \includegraphics[width=0.44\textwidth]{pretty_QB_Toulouse_Ortho_PXS.eps}
  // \itkcaption[Pan sharpening]{Result of applying
  // the \doxygen{otb}{SimpleRcsPanSharpeningFusionImageFilter} to
  // orthorectified Quickbird
  // image. From left to right : original PAN image, original XS image and the
  // result of the PAN sharpening}
  // \label{fig:PANSHARP_FILTER}
  // \end{figure}
  //
  // Software Guide : EndLatex

}
<|endoftext|>


<commit_before><commit_msg>Cleaning up code.<commit_after><|endoftext|>


<commit_before>// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/nacl/loader/nacl_sandbox_linux.h"

#include <signal.h>
#include <sys/ptrace.h>

#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "build/build_config.h"
#include "content/public/common/sandbox_init.h"
#include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
#include "sandbox/linux/services/linux_syscalls.h"

using playground2::ErrorCode;
using playground2::Sandbox;

namespace {

// On ARM and x86_64, System V shared memory calls have each their own system
// call, while on i386 they are multiplexed.
#if defined(__x86_64__) || defined(__arm__)
bool IsSystemVSharedMemory(int sysno) {
  switch (sysno) {
    case __NR_shmat:
    case __NR_shmctl:
    case __NR_shmdt:
    case __NR_shmget:
      return true;
    default:
      return false;
  }
}
#endif

#if defined(__i386__)
// Big system V multiplexing system call.
bool IsSystemVIpc(int sysno) {
  switch (sysno) {
    case __NR_ipc:
      return true;
    default:
      return false;
  }
}
#endif

ErrorCode NaClBpfSandboxPolicy(
    playground2::Sandbox* sb, int sysno, void* aux) {
  const playground2::BpfSandboxPolicyCallback baseline_policy =
      content::GetBpfSandboxBaselinePolicy();
  switch (sysno) {
    // TODO(jln): NaCl's GDB debug stub uses the following socket system calls,
    // see if it can be restricted a bit.
#if defined(__x86_64__) || defined(__arm__)
    // transport_common.cc needs this.
    case __NR_accept:
    case __NR_setsockopt:
#elif defined(__i386__)
    case __NR_socketcall:
#endif
    // trusted/service_runtime/linux/thread_suspension.c needs sigwait() and is
    // used by NaCl's GDB debug stub.
    case __NR_rt_sigtimedwait:
#if defined(__i386__)
    // Needed on i386 to set-up the custom segments.
    case __NR_modify_ldt:
#endif
    // NaClAddrSpaceBeforeAlloc needs prlimit64.
    case __NR_prlimit64:
    // NaCl uses custom signal stacks.
    case __NR_sigaltstack:
    // Below is fairly similar to the policy for a Chromium renderer.
    // TODO(jln): restrict clone(), ioctl() and prctl().
    case __NR_ioctl:
#if defined(__i386__) || defined(__x86_64__)
    case __NR_getrlimit:
#endif
#if defined(__i386__) || defined(__arm__)
    case __NR_ugetrlimit:
#endif
    case __NR_pread64:
    case __NR_pwrite64:
    case __NR_sched_get_priority_max:
    case __NR_sched_get_priority_min:
    case __NR_sched_getaffinity:
    case __NR_sched_getparam:
    case __NR_sched_getscheduler:
    case __NR_sched_setscheduler:
    case __NR_setpriority:
    case __NR_sysinfo:
    // __NR_times needed as clock() is called by CommandBufferHelper, which is
    // used by NaCl applications that use Pepper's 3D interfaces.
    // See crbug.com/264856 for details.
    case __NR_times:
    case __NR_uname:
      return ErrorCode(ErrorCode::ERR_ALLOWED);
    case __NR_ptrace:
      return ErrorCode(EPERM);
    default:
      // TODO(jln): look into getting rid of System V shared memory:
      // platform_qualify/linux/sysv_shm_and_mmap.c makes it a requirement, but
      // it may not be needed in all cases. Chromium renderers don't need
      // System V shared memory on Aura.
#if defined(__x86_64__) || defined(__arm__)
      if (IsSystemVSharedMemory(sysno))
        return ErrorCode(ErrorCode::ERR_ALLOWED);
#elif defined(__i386__)
      if (IsSystemVIpc(sysno))
        return ErrorCode(ErrorCode::ERR_ALLOWED);
#endif
      return baseline_policy.Run(sb, sysno, aux);
  }
  NOTREACHED();
  // GCC wants this.
  return ErrorCode(EPERM);
}

void RunSandboxSanityChecks() {
  errno = 0;
  // Make a ptrace request with an invalid PID.
  long ptrace_ret = ptrace(PTRACE_PEEKUSER, -1 /* pid */, NULL, NULL);
  CHECK_EQ(-1, ptrace_ret);
  // Without the sandbox on, this ptrace call would ESRCH instead.
  CHECK_EQ(EPERM, errno);
}

}  // namespace

bool InitializeBpfSandbox() {
  bool sandbox_is_initialized =
      content::InitializeSandbox(NaClBpfSandboxPolicy);
  if (sandbox_is_initialized) {
    RunSandboxSanityChecks();
    // TODO(jln): Find a way to fix this.
    // The sandbox' SIGSYS handler trips NaCl, so we disable it.
    // If SIGSYS is triggered it'll now execute the default action
    // (CORE). This will make it hard to track down bugs and sandbox violations.
    CHECK(signal(SIGSYS, SIG_DFL) != SIG_ERR);
    return true;
  }
  return false;
}
<commit_msg>Add clock_getres to allowed NaCl syscalls.<commit_after>// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/nacl/loader/nacl_sandbox_linux.h"

#include <signal.h>
#include <sys/ptrace.h>

#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "build/build_config.h"
#include "content/public/common/sandbox_init.h"
#include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
#include "sandbox/linux/services/linux_syscalls.h"

using playground2::ErrorCode;
using playground2::Sandbox;

namespace {

// On ARM and x86_64, System V shared memory calls have each their own system
// call, while on i386 they are multiplexed.
#if defined(__x86_64__) || defined(__arm__)
bool IsSystemVSharedMemory(int sysno) {
  switch (sysno) {
    case __NR_shmat:
    case __NR_shmctl:
    case __NR_shmdt:
    case __NR_shmget:
      return true;
    default:
      return false;
  }
}
#endif

#if defined(__i386__)
// Big system V multiplexing system call.
bool IsSystemVIpc(int sysno) {
  switch (sysno) {
    case __NR_ipc:
      return true;
    default:
      return false;
  }
}
#endif

ErrorCode NaClBpfSandboxPolicy(
    playground2::Sandbox* sb, int sysno, void* aux) {
  const playground2::BpfSandboxPolicyCallback baseline_policy =
      content::GetBpfSandboxBaselinePolicy();
  switch (sysno) {
    // TODO(jln): NaCl's GDB debug stub uses the following socket system calls,
    // see if it can be restricted a bit.
#if defined(__x86_64__) || defined(__arm__)
    // transport_common.cc needs this.
    case __NR_accept:
    case __NR_setsockopt:
#elif defined(__i386__)
    case __NR_socketcall:
#endif
    // trusted/service_runtime/linux/thread_suspension.c needs sigwait() and is
    // used by NaCl's GDB debug stub.
    case __NR_rt_sigtimedwait:
#if defined(__i386__)
    // Needed on i386 to set-up the custom segments.
    case __NR_modify_ldt:
#endif
    // NaClAddrSpaceBeforeAlloc needs prlimit64.
    case __NR_prlimit64:
    // NaCl uses custom signal stacks.
    case __NR_sigaltstack:
    // Below is fairly similar to the policy for a Chromium renderer.
    // TODO(jln): restrict clone(), ioctl() and prctl().
    case __NR_ioctl:
#if defined(__i386__) || defined(__x86_64__)
    case __NR_getrlimit:
#endif
#if defined(__i386__) || defined(__arm__)
    case __NR_ugetrlimit:
#endif
    // NaCl runtime exposes clock_getres to untrusted code.
    case __NR_clock_getres:
    case __NR_pread64:
    case __NR_pwrite64:
    case __NR_sched_get_priority_max:
    case __NR_sched_get_priority_min:
    case __NR_sched_getaffinity:
    case __NR_sched_getparam:
    case __NR_sched_getscheduler:
    case __NR_sched_setscheduler:
    case __NR_setpriority:
    case __NR_sysinfo:
    // __NR_times needed as clock() is called by CommandBufferHelper, which is
    // used by NaCl applications that use Pepper's 3D interfaces.
    // See crbug.com/264856 for details.
    case __NR_times:
    case __NR_uname:
      return ErrorCode(ErrorCode::ERR_ALLOWED);
    case __NR_ptrace:
      return ErrorCode(EPERM);
    default:
      // TODO(jln): look into getting rid of System V shared memory:
      // platform_qualify/linux/sysv_shm_and_mmap.c makes it a requirement, but
      // it may not be needed in all cases. Chromium renderers don't need
      // System V shared memory on Aura.
#if defined(__x86_64__) || defined(__arm__)
      if (IsSystemVSharedMemory(sysno))
        return ErrorCode(ErrorCode::ERR_ALLOWED);
#elif defined(__i386__)
      if (IsSystemVIpc(sysno))
        return ErrorCode(ErrorCode::ERR_ALLOWED);
#endif
      return baseline_policy.Run(sb, sysno, aux);
  }
  NOTREACHED();
  // GCC wants this.
  return ErrorCode(EPERM);
}

void RunSandboxSanityChecks() {
  errno = 0;
  // Make a ptrace request with an invalid PID.
  long ptrace_ret = ptrace(PTRACE_PEEKUSER, -1 /* pid */, NULL, NULL);
  CHECK_EQ(-1, ptrace_ret);
  // Without the sandbox on, this ptrace call would ESRCH instead.
  CHECK_EQ(EPERM, errno);
}

}  // namespace

bool InitializeBpfSandbox() {
  bool sandbox_is_initialized =
      content::InitializeSandbox(NaClBpfSandboxPolicy);
  if (sandbox_is_initialized) {
    RunSandboxSanityChecks();
    // TODO(jln): Find a way to fix this.
    // The sandbox' SIGSYS handler trips NaCl, so we disable it.
    // If SIGSYS is triggered it'll now execute the default action
    // (CORE). This will make it hard to track down bugs and sandbox violations.
    CHECK(signal(SIGSYS, SIG_DFL) != SIG_ERR);
    return true;
  }
  return false;
}
<|endoftext|>


<commit_before>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3188
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3188 to 3189<commit_after>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3189
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3294
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3294 to 3295<commit_after>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3295
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3393
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3393 to 3394<commit_after>/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3394
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3165
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3165 to 3166<commit_after>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3166
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>/*=========================================================================
 *
 *  Copyright Insight Software Consortium
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

#include "itkLabelImageToShapeLabelMapFilter.h"
#include "itkTestingMacros.h"
#include "itkMath.h"

namespace m = itk::Math;

int itkLabelImageToShapeLabelMapFilterTest2(int , char *[])
{

  const unsigned int dim = 2;

  typedef unsigned char PixelType;

  typedef itk::Image< PixelType, dim > ImageType;

  typedef itk::ShapeLabelObject< PixelType, dim >     LabelObjectType;
  typedef itk::LabelMap< LabelObjectType >            LabelMapType;

  ImageType::RegionType region;
  ImageType::SizeType size;
  size[0] = 11;
  size[1] = 13;
  ImageType::IndexType index;
  index.Fill(0);
  region.SetSize(size);
  region.SetIndex(index);

  LabelMapType::Pointer labelMap;
  LabelObjectType::Pointer labelObject;

  LabelObjectType::OrientedBoundingBoxPointType obbOrigin;
  LabelObjectType::OrientedBoundingBoxSizeType  obbSize;

  ImageType::Pointer image = ImageType::New();
  image->SetRegions(region);
  image->Allocate();

  //
  // Test case one pixel
  //

  index[0] = 5;
  index[1] = 7;
  image->SetPixel(index, 1);

  typedef itk::LabelImageToShapeLabelMapFilter< ImageType, LabelMapType> L2SType;
  L2SType::Pointer l2s = L2SType::New();
  l2s->SetInput( image );

  TRY_EXPECT_NO_EXCEPTION( l2s->Update() );

  labelMap = l2s->GetOutput();
  labelObject = labelMap->GetLabelObject(1);

  obbSize = labelObject->GetOrientedBoundingBoxSize();
  obbOrigin = labelObject->GetOrientedBoundingBoxOrigin();
  TEST_EXPECT_TRUE( m::AlmostEquals(obbSize[0], 1.0) && m::AlmostEquals(obbSize[1], 1.0));

  //
  // Test case two diagonal pixels
  //

  ++index[0];
  ++index[1];

  image->SetPixel(index, 1);
  image->Modified();

  TRY_EXPECT_NO_EXCEPTION( l2s->Update() );

  labelMap = l2s->GetOutput();
  labelObject = labelMap->GetLabelObject(1);

  obbSize = labelObject->GetOrientedBoundingBoxSize();
  obbOrigin = labelObject->GetOrientedBoundingBoxOrigin();
  TEST_EXPECT_TRUE( m::AlmostEquals(obbSize[0], m::sqrt2) && m::AlmostEquals(obbSize[1], 2.0*m::sqrt2));
  TEST_EXPECT_TRUE( m::AlmostEquals(obbOrigin[0], 4.0) && m::AlmostEquals(obbOrigin[1], 7.0));

  //
  // Test case two diagonal pixels, with flip direction matrix
  //
  ImageType::DirectionType direction;
  direction.Fill(0.0);
  direction(0,1) = 1.0;
  direction(1,0) = 1.0;

  image->SetDirection(direction);
  image->Modified();

  TRY_EXPECT_NO_EXCEPTION( l2s->Update() );

  labelMap = l2s->GetOutput();
  labelObject = labelMap->GetLabelObject(1);

  obbSize = labelObject->GetOrientedBoundingBoxSize();
  obbOrigin = labelObject->GetOrientedBoundingBoxOrigin();
  TEST_EXPECT_TRUE( m::AlmostEquals(obbSize[0], m::sqrt2) && m::AlmostEquals(obbSize[1], 2.0*m::sqrt2));
  TEST_EXPECT_TRUE( m::AlmostEquals(obbOrigin[0], 6.0) && m::AlmostEquals(obbOrigin[1], 5.0));

  //
  // Test case 2x4 rectangle
  //
  image->FillBuffer(0);
  direction.SetIdentity();
  image->SetDirection(direction);
  for (unsigned int i = 4; i < 6; ++i)
    {
    for (unsigned int j = 3; j < 7; ++j)
      {
      ImageType::IndexType idx;
      idx[0] = i;
      idx[1] = j;
      image->SetPixel(idx, 1);
      }
    }

  image->Modified();

  TRY_EXPECT_NO_EXCEPTION( l2s->Update() );

  labelMap = l2s->GetOutput();
  labelObject = labelMap->GetLabelObject(1);

  obbSize = labelObject->GetOrientedBoundingBoxSize();
  obbOrigin = labelObject->GetOrientedBoundingBoxOrigin();
  std::cout << labelObject;
  TEST_EXPECT_TRUE( m::AlmostEquals(obbSize[0], 2.0) && m::AlmostEquals(obbSize[1], 4.0));
  TEST_EXPECT_TRUE( m::AlmostEquals(obbOrigin[0], 3.5) && m::AlmostEquals(obbOrigin[1], 2.5));

  // Just exercise these methods
  std::cout << "OBB vericies: " << labelObject->GetOrientedBoundingBoxVertices() << std::endl;
  std::cout << "OBB direction: " << labelObject->GetOrientedBoundingBoxDirection();

  return EXIT_SUCCESS;
}
<commit_msg>BUG: Initialize image data to 0<commit_after>/*=========================================================================
 *
 *  Copyright Insight Software Consortium
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

#include "itkLabelImageToShapeLabelMapFilter.h"
#include "itkTestingMacros.h"
#include "itkMath.h"

namespace m = itk::Math;

int itkLabelImageToShapeLabelMapFilterTest2(int , char *[])
{

  const unsigned int dim = 2;

  typedef unsigned char PixelType;

  typedef itk::Image< PixelType, dim > ImageType;

  typedef itk::ShapeLabelObject< PixelType, dim >     LabelObjectType;
  typedef itk::LabelMap< LabelObjectType >            LabelMapType;

  ImageType::RegionType region;
  ImageType::SizeType size;
  size[0] = 11;
  size[1] = 13;
  ImageType::IndexType index;
  index.Fill(0);
  region.SetSize(size);
  region.SetIndex(index);

  LabelMapType::Pointer labelMap;
  LabelObjectType::Pointer labelObject;

  LabelObjectType::OrientedBoundingBoxPointType obbOrigin;
  LabelObjectType::OrientedBoundingBoxSizeType  obbSize;

  ImageType::Pointer image = ImageType::New();
  image->SetRegions(region);
  image->Allocate(true);

  //
  // Test case one pixel
  //

  index[0] = 5;
  index[1] = 7;
  image->SetPixel(index, 1);

  typedef itk::LabelImageToShapeLabelMapFilter< ImageType, LabelMapType> L2SType;
  L2SType::Pointer l2s = L2SType::New();
  l2s->SetInput( image );

  TRY_EXPECT_NO_EXCEPTION( l2s->Update() );

  labelMap = l2s->GetOutput();
  labelObject = labelMap->GetLabelObject(1);

  obbSize = labelObject->GetOrientedBoundingBoxSize();
  obbOrigin = labelObject->GetOrientedBoundingBoxOrigin();
  TEST_EXPECT_TRUE( m::AlmostEquals(obbSize[0], 1.0) && m::AlmostEquals(obbSize[1], 1.0));

  //
  // Test case two diagonal pixels
  //

  ++index[0];
  ++index[1];

  image->SetPixel(index, 1);
  image->Modified();

  TRY_EXPECT_NO_EXCEPTION( l2s->Update() );

  labelMap = l2s->GetOutput();
  labelObject = labelMap->GetLabelObject(1);

  obbSize = labelObject->GetOrientedBoundingBoxSize();
  obbOrigin = labelObject->GetOrientedBoundingBoxOrigin();
  TEST_EXPECT_TRUE( m::AlmostEquals(obbSize[0], m::sqrt2) && m::AlmostEquals(obbSize[1], 2.0*m::sqrt2));
  TEST_EXPECT_TRUE( m::AlmostEquals(obbOrigin[0], 4.0) && m::AlmostEquals(obbOrigin[1], 7.0));

  //
  // Test case two diagonal pixels, with flip direction matrix
  //
  ImageType::DirectionType direction;
  direction.Fill(0.0);
  direction(0,1) = 1.0;
  direction(1,0) = 1.0;

  image->SetDirection(direction);
  image->Modified();

  TRY_EXPECT_NO_EXCEPTION( l2s->Update() );

  labelMap = l2s->GetOutput();
  labelObject = labelMap->GetLabelObject(1);

  obbSize = labelObject->GetOrientedBoundingBoxSize();
  obbOrigin = labelObject->GetOrientedBoundingBoxOrigin();
  TEST_EXPECT_TRUE( m::AlmostEquals(obbSize[0], m::sqrt2) && m::AlmostEquals(obbSize[1], 2.0*m::sqrt2));
  TEST_EXPECT_TRUE( m::AlmostEquals(obbOrigin[0], 6.0) && m::AlmostEquals(obbOrigin[1], 5.0));

  //
  // Test case 2x4 rectangle
  //
  image->FillBuffer(0);
  direction.SetIdentity();
  image->SetDirection(direction);
  for (unsigned int i = 4; i < 6; ++i)
    {
    for (unsigned int j = 3; j < 7; ++j)
      {
      ImageType::IndexType idx;
      idx[0] = i;
      idx[1] = j;
      image->SetPixel(idx, 1);
      }
    }

  image->Modified();

  TRY_EXPECT_NO_EXCEPTION( l2s->Update() );

  labelMap = l2s->GetOutput();
  labelObject = labelMap->GetLabelObject(1);

  obbSize = labelObject->GetOrientedBoundingBoxSize();
  obbOrigin = labelObject->GetOrientedBoundingBoxOrigin();
  std::cout << labelObject;
  TEST_EXPECT_TRUE( m::AlmostEquals(obbSize[0], 2.0) && m::AlmostEquals(obbSize[1], 4.0));
  TEST_EXPECT_TRUE( m::AlmostEquals(obbOrigin[0], 3.5) && m::AlmostEquals(obbOrigin[1], 2.5));

  // Just exercise these methods
  std::cout << "OBB vertices: " << labelObject->GetOrientedBoundingBoxVertices() << std::endl;
  std::cout << "OBB direction: " << labelObject->GetOrientedBoundingBoxDirection();

  return EXIT_SUCCESS;
}
<|endoftext|>


<commit_before>{% extends 'scan.cpp' %}

{% block initializer %}std::tuple_cat({{ super() }}, make_tuple({{mapping_var_name}}.second)){% endblock %}<commit_msg>add std:: in previous commit<commit_after>{% extends 'scan.cpp' %}

{% block initializer %}std::tuple_cat({{ super() }}, std::make_tuple({{mapping_var_name}}.second)){% endblock %}<|endoftext|>