コード例 #1
0
int ColorMapBulletNewApproachVolumeSampling(int argc, char** argv, boost::shared_ptr<ElVis::Model> model, unsigned int width, unsigned int height, const std::string& outFilePath)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
    glutInitWindowSize(100, 100);
    glutCreateWindow("fake");

    boost::shared_ptr<ElVis::Scene> scene(new ElVis::Scene());
    scene->SetModel(model);

    boost::shared_ptr<ElVis::Cylinder> cylinder(new ElVis::Cylinder());
    cylinder->GetTransformationMatrix()[11] = 2.0;

    cylinder->GetTransformationMatrix()[0] = .10001f;
    cylinder->GetTransformationMatrix()[5] = .10001f;
    cylinder->GetTransformationMatrix()[10] = .4f;
   
    
    ElVis::PointLight* l = new ElVis::PointLight();
    ElVis::Color lightColor;
    lightColor.SetRed(.5);
    lightColor.SetGreen(.5);
    lightColor.SetBlue(.5);

    ElVis::WorldPoint lightPos(10.0, 0.0, 0.0);
    l->SetColor(lightColor);
    l->SetPosition(lightPos);
    scene->AddLight(l);

    ElVis::Color ambientColor;
    ambientColor.SetRed(.5);
    ambientColor.SetGreen(.5);
    ambientColor.SetBlue(.5);
    scene->SetAmbientLightColor(ambientColor);
    
    boost::shared_ptr<ElVis::Triangle> triangle1(new ElVis::Triangle());
    triangle1->SetP0(ElVis::WorldPoint(0, -1, 0));
    triangle1->SetP1(ElVis::WorldPoint(0, -1, 18));
    triangle1->SetP2(ElVis::WorldPoint(0, 1, 18));

    boost::shared_ptr<ElVis::Triangle> triangle2(new ElVis::Triangle());
    triangle2->SetP0(ElVis::WorldPoint(0, -1, 0));
    triangle2->SetP2(ElVis::WorldPoint(0, 1, 0));
    triangle2->SetP1(ElVis::WorldPoint(0, 1, 18));
  
    ElVis::Cylinder* cylinderToMap = new ElVis::Cylinder();
    cylinderToMap->GetTransformationMatrix()[11] = 0;

    cylinderToMap->GetTransformationMatrix()[0] = .1f;
    cylinderToMap->GetTransformationMatrix()[5] = .1f;
    cylinderToMap->GetTransformationMatrix()[10] = 20.0f;

    boost::shared_ptr<ElVis::PrimaryRayModule> primaryRayModule(new ElVis::PrimaryRayModule());
    boost::shared_ptr<ElVis::SampleVolumeSamplerObject> t1Sampler(new ElVis::SampleVolumeSamplerObject(triangle1));
    boost::shared_ptr<ElVis::SampleVolumeSamplerObject> t2Sampler(new ElVis::SampleVolumeSamplerObject(triangle2));
    //boost::shared_ptr<ElVis::SurfaceObject> cylinderSurface(new ElVis::SurfaceObject(cylinder));
    boost::shared_ptr<ElVis::SampleVolumeSamplerObject> cylinderSurface(new ElVis::SampleVolumeSamplerObject(cylinder));
    primaryRayModule->AddObject(t1Sampler);
    primaryRayModule->AddObject(t2Sampler);
    primaryRayModule->AddObject(cylinderSurface);

    boost::shared_ptr<ElVis::ColorMapperModule> colorMapperModule(new ElVis::ColorMapperModule());

    boost::shared_ptr<ElVis::TextureColorMap> textureColorMapper(new ElVis::TextureColorMap(ElVis::GetColorMapPath() + "/diverging257.cmap"));
    textureColorMapper->SetMin(-.12);
    textureColorMapper->SetMax(0);
    colorMapperModule->SetColorMap(textureColorMapper);
   
    
    ElVis::Camera c;

    // Zoomed to region of interest.
    //c.SetParameters(ElVis::WorldPoint(.5, 0, 1.5), ElVis::WorldPoint(0, 0, 1.5), ElVis::WorldVector(0, 1, 0));

    // Overall view
    //c.SetParameters(ElVis::WorldPoint(6, 0, 3.5), ElVis::WorldPoint(0, 0, 3.5), ElVis::WorldVector(0, 1, 0));

    //c.SetParameters(ElVis::WorldPoint(1.8, 1.2, 3.0), ElVis::WorldPoint(0, 0, 1), ElVis::WorldVector(0, 1, 0));
    c.SetParameters(ElVis::WorldPoint(1.8, .46, 3.7), ElVis::WorldPoint(0, 0, 2.7), ElVis::WorldVector(0, 1, 0));

    boost::shared_ptr<ElVis::SceneView> view(new ElVis::SceneView());
    view->SetCamera(c);
    
    boost::shared_ptr<ElVis::LightingModule> lighting(new ElVis::LightingModule());


    view->AddRenderModule(primaryRayModule);
    view->AddRenderModule(colorMapperModule);
    view->AddRenderModule(lighting);
    view->SetScene(scene);
    view->Resize(width, height);
    
    //view->GetScene()->SetEnableOptixTrace(true);
    //ElVis::Point<int, ElVis::TwoD> pixel1(10, 10);
    //view->GetScene()->SetOptixTracePixelIndex(pixel1);
    
    view->Draw();

    //std::cout << "Second pixel." << std::endl;
    //ElVis::Point<int, ElVis::TwoD> pixel(10, 1000-10-1);
    //view->GetScene()->SetOptixTracePixelIndex(pixel);
    //view->Draw();

    //ElVis::Point<int, ElVis::TwoD> pixel2(10, 1000-10-1);
    //view->GetScene()->SetOptixTracePixelIndex(pixel2);
    //view->GetScene()->SetEnableOptixTrace(true);
    //view->Draw();



    view->WriteColorBufferToFile(outFilePath.c_str());
    return 0;
}
コード例 #2
0
ファイル: Breakpoints.cpp プロジェクト: Nasrollah/ElVis
        bool Breakpoints::eventFilter(QObject *object, QEvent *event)
        {
            if( object != m_widget )
            {
                return false;
            }

            switch (event->type()) 
            {
                case QEvent::MouseButtonPress:
                {
                    QMouseEvent *me = (QMouseEvent *) event;
                    QPointF clickPos = me->pos();

                    for(m_selectedBreakpoint = m_model->GetBreakpoints().begin(); m_selectedBreakpoint != m_model->GetBreakpoints().end(); ++m_selectedBreakpoint)
                    {
                        QPainterPath path;
                        path.addEllipse(pointBoundingRect(m_selectedBreakpoint));
                        if (path.contains(clickPos)) 
                        {
                            break;
                        }
                    }

                    if (me->button() == Qt::LeftButton) 
                    {
                        if (m_selectedBreakpoint == m_model->GetBreakpoints().end() ) 
                        {
                            double px, py;
                            CalculatePercent(clickPos.x(), clickPos.y(), px, py);
                            ElVis::Color c;
                            c.SetAlpha(py);
                            c.SetGreen(1.0);
                            c.SetRed(1.0);
                            c.SetBlue(1.0);
                            m_selectedBreakpoint = m_model->InsertBreakpoint(px, c);
                        } 
                    } 
                    else if (me->button() == Qt::RightButton) 
                    {
                        if( m_selectedBreakpoint != m_model->GetBreakpoints().end() )
                        {
                            m_model->RemoveBreakpoint(m_selectedBreakpoint);
                            m_selectedBreakpoint = m_model->GetBreakpoints().end();
                        }
                    }
                    OnSelectedPointChanged(m_selectedBreakpoint);
                    OnBreakpointsChanged();
                    return true;
                }
                break;

                case QEvent::MouseButtonRelease:
                    break;

                case QEvent::MouseMove:
                    if (m_selectedBreakpoint != m_model->GetBreakpoints().end() )
                    {
                        const QPointF& point = ((QMouseEvent *)event)->pos();
                        double px, py;
                        CalculatePercent(point.x(), point.y(), px, py);

                        ElVisFloat key = px;
                        while( m_model->GetBreakpoints().find(key) != m_model->GetBreakpoints().end())
                        {
                            key += .00001;
                        }

                        ElVis::Color c = (*m_selectedBreakpoint).second.Col;
                        c.SetAlpha(py);
                        m_model->RemoveBreakpoint(m_selectedBreakpoint);
                        m_selectedBreakpoint = m_model->InsertBreakpoint(key, c);
                        OnBreakpointsChanged();
                    }
                    break;

                case QEvent::Resize:
                {
                    //QResizeEvent *e = (QResizeEvent *) event;
                    //if (e->oldSize().width() == 0 || e->oldSize().height() == 0)
                    //    break;
                    //qreal stretch_x = e->size().width() / qreal(e->oldSize().width());
                    //qreal stretch_y = e->size().height() / qreal(e->oldSize().height());
                    //for (int i=0; i<m_points.size(); ++i) 
                    //{
                    //    QPointF p = m_points[i];
                    //    movePoint(i, QPointF(p.x() * stretch_x, p.y() * stretch_y), false);
                    //}

                    //update();
                    break;
                }

                case QEvent::Paint:
                {
                    ColorMapRect* that_widget = m_widget;
                    m_widget = 0;
                    QApplication::sendEvent(object, event);
                    m_widget = that_widget;
                    paintPoints();
                    return true;
                }
                default:
                    break;
            }

            return false;
        }
コード例 #3
0
int GenericCLIInterface(int argc, char** argv,
                        boost::shared_ptr<ElVis::Scene> scene,
                        boost::shared_ptr<ElVis::Model> model,
                        boost::shared_ptr<ElVis::ColorMap> colorMap,
                        unsigned int width, unsigned int height, const std::string& outFilePath, const ElVis::Camera& c)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
    glutInitWindowSize(100, 100);
    glutCreateWindow("fake");

    std::cout << "Generic CLI Interface." << std::endl;
    const char* isovaluesLabel = "Isovalues";
    const char* isosurfaceModuleEnabledLabel = "IsosurfaceModuleEnabled";
    const char* volumeRenderingModuleEnabledLabel = "VolumeRenderingModuleEnabled";
    const char* contourModuleEnabledLabel = "ContourModuleEnabled";
    const char* meshModuleEnabledLabel = "MeshModuleEnabled";
    const char* boundarySurfacesLabel = "BoundarySurfaces";

    // Volume Rendering labels
    const char* integrationTypeLabel = "IntegrationType";
    const char* breakpointLabel = "Breakpoints";
    const char* colorsLabel = "Colors";
    const char* hLabel = "h";
    const char* epsilonLabel = "Epsilon";
    const char* traceLabel = "EnableTrace";
    const char* traceXLabel = "TraceX";
    const char* traceYLabel = "TraceY";
    const char* trackNumSamplesLabel = "TrackNumSamples";
    const char* renderIntegrationTypeLabel = "RenderIntegrationType";
    const char* emptySpaceSkippingLabel = "EnableEmptySpaceSkipping";

    const char* cutPlaneNormalLabel = "CutPlaneNormal";
    const char* cutPlanePointLabel= "CutPlanePoint";
    const char* fieldLabel="Field";

    const char* numTestsLabel = "NumTests";

    std::vector<double> cutPlaneNormal;
    std::vector<double> cutPlanePoint;
    std::vector<double> breakpoints;
    std::vector<double> colors;
    std::vector<int> boundarySurfaces;
    std::vector<double> isovalues;
    bool isosurfaceModuleEnabled = false;
    bool volumeRenderingModuleEnabled = false;
    bool contourModuleEnabled = false;
    bool meshModuleEnabled = false;
    unsigned int numTests = 1;
    std::string configFile;
    int fieldIndex = 0;

    boost::program_options::options_description desc("GenericCLIOptions");
    desc.add_options()
        (isovaluesLabel, boost::program_options::value<std::vector<double> >(&isovalues)->multitoken(), "Isovalues")
        (boundarySurfacesLabel, boost::program_options::value<std::vector<int> >(&boundarySurfaces)->multitoken(), "Boundary Surfaces")
        (isosurfaceModuleEnabledLabel, boost::program_options::value<bool>(&isosurfaceModuleEnabled), "Isosurface Module Enabled")
        (volumeRenderingModuleEnabledLabel, boost::program_options::value<bool>(&volumeRenderingModuleEnabled), "Volume Rendering Module Enabled")
        (contourModuleEnabledLabel, boost::program_options::value<bool>(&contourModuleEnabled), "Contour Module Enabled")
        (meshModuleEnabledLabel, boost::program_options::value<bool>(&meshModuleEnabled), "Mesh Module Enabled")
        (integrationTypeLabel, boost::program_options::value<int>(), "Integration Type")
        (breakpointLabel, boost::program_options::value<std::vector<double> >(&breakpoints)->multitoken(), "Breakpoints")
        (colorsLabel, boost::program_options::value<std::vector<double> >(&colors)->multitoken(), "Colors")
        (hLabel, boost::program_options::value<double>(), "h")
        (epsilonLabel, boost::program_options::value<double>(), "Epsilon")
        (traceLabel, boost::program_options::value<int>(), "Enable Trace")
        (traceXLabel, boost::program_options::value<int>(), "Trace X")
        (traceYLabel, boost::program_options::value<int>(), "Trace Y")
        (trackNumSamplesLabel, boost::program_options::value<int>(), "Track Num Samples")
        (renderIntegrationTypeLabel, boost::program_options::value<int>(), "RenderIntegrationType")
        (emptySpaceSkippingLabel, boost::program_options::value<int>(), "EnableEmptySpaceSkipping")
        (numTestsLabel, boost::program_options::value<unsigned int>(&numTests), "Number of Tests")
        (cutPlaneNormalLabel, boost::program_options::value<std::vector<double> >(&cutPlaneNormal)->multitoken(), "Cut Plane Normal")
        (cutPlanePointLabel, boost::program_options::value<std::vector<double> >(&cutPlanePoint)->multitoken(), "Cut Plane Point")
        (fieldLabel, boost::program_options::value<int>(&fieldIndex), "Field Index")
        ;

    const char* configFileNameLabel = "ConfigFile";

    boost::program_options::options_description configFileOptions("ConfigFileOptions");
    configFileOptions.add_options()
            (configFileNameLabel, boost::program_options::value<std::string>(&configFile), "Config File")
            ;

    boost::program_options::options_description commandLineOptions("CommandLineOptions");
    commandLineOptions.add(desc).add(configFileOptions);


    boost::program_options::variables_map vm;
    boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(commandLineOptions).style(boost::program_options::command_line_style::allow_long |
                                                                                                              boost::program_options::command_line_style::long_allow_adjacent).allow_unregistered().run(), vm);
    boost::program_options::notify(vm);

    if( !configFile.empty() )
    {
        std::ifstream inFile(configFile.c_str());
        if( inFile )
        {
            boost::program_options::store(boost::program_options::parse_config_file(inFile, desc, true), vm);
            boost::program_options::notify(vm);
        }
        inFile.close();
    }

    #ifdef __GNUC__
    system("nvidia-smi");
    #endif

    ElVis::PointLight* l = new ElVis::PointLight();
    ElVis::Color lightColor;
    lightColor.SetRed(.5);
    lightColor.SetGreen(.5);
    lightColor.SetBlue(.5);

    ElVis::WorldPoint lightPos(10.0, 0.0, 0.0);
    l->SetColor(lightColor);
    l->SetPosition(lightPos);
    scene->AddLight(l);

    ElVis::Color ambientColor;
    ambientColor.SetRed(.5);
    ambientColor.SetGreen(.5);
    ambientColor.SetBlue(.5);
    scene->SetAmbientLightColor(ambientColor);

    boost::shared_ptr<ElVis::SceneView> view(new ElVis::SceneView());
    view->SetCamera(c);


    view->SetScalarFieldIndex(fieldIndex);

    boost::shared_ptr<ElVis::PrimaryRayModule> primaryRayModule(new ElVis::PrimaryRayModule());
    view->AddRenderModule(primaryRayModule);

    if( cutPlaneNormal.size() == 3 &&
        cutPlanePoint.size() == 3 )
    {
        ElVis::WorldPoint normal(cutPlaneNormal[0], cutPlaneNormal[1], cutPlaneNormal[2]);
        ElVis::WorldPoint p(cutPlanePoint[0], cutPlanePoint[1], cutPlanePoint[2]);
        
        boost::shared_ptr<ElVis::Plane> cutPlane(new ElVis::Plane(normal, p));
        boost::shared_ptr<ElVis::SampleVolumeSamplerObject> sampler(new ElVis::SampleVolumeSamplerObject(cutPlane));
        primaryRayModule->AddObject(sampler);
    }

    if( contourModuleEnabled )
    {
        std::cout << "Contour Module enabled.  Number of isovalues = " << isovalues.size() << std::endl;
        boost::shared_ptr<ElVis::CutSurfaceContourModule> contourModule(new ElVis::CutSurfaceContourModule());
        view->AddRenderModule(contourModule);

        for(unsigned int i = 0; i < isovalues.size(); ++i)
        {
            contourModule->AddIsovalue(isovalues[i]);
        }
    }

    if( meshModuleEnabled )
    {
        boost::shared_ptr<ElVis::CutSurfaceMeshModule> meshModule(new ElVis::CutSurfaceMeshModule());
        view->AddRenderModule(meshModule);
    }

    if( isosurfaceModuleEnabled )
    {
        boost::shared_ptr<ElVis::IsosurfaceModule> isosurfaceModule(new ElVis::IsosurfaceModule());
        view->AddRenderModule(isosurfaceModule);

        for(unsigned int i = 0; i < isovalues.size(); ++i)
        {
            isosurfaceModule->AddIsovalue(isovalues[i]);
        }
    }

    boost::shared_ptr<ElVis::ColorMapperModule> colorMapperModule(new ElVis::ColorMapperModule());
    view->AddRenderModule(colorMapperModule);
    colorMapperModule->SetColorMap(colorMap);

    if( boundarySurfaces.size() > 0)
    {
        boost::shared_ptr<ElVis::FaceObject> faceObject(new ElVis::FaceObject(scene));
        boost::shared_ptr<ElVis::SampleFaceObject> obj(new ElVis::SampleFaceObject(faceObject));
        primaryRayModule->AddObject(obj);
        for(int i = 0; i < boundarySurfaces.size(); ++i)
        {
            std::vector<int> faceIds;
            std::string boundaryName;
            model->GetBoundarySurface(boundarySurfaces[i], boundaryName, faceIds);

            if( faceIds.empty() ) continue;

            for(unsigned int j = 0; j < faceIds.size(); ++j)
            {
                obj->EnableFace(faceIds[j]);
            }
        }
    }

    if( volumeRenderingModuleEnabled )
    {
        if( vm.count(integrationTypeLabel) == 0 )
        {
            return 1;
        }

        if( breakpoints.size()*4 != colors.size() )
        {
            std::cerr << "Invalid transfer specification." << std::endl;
            std::cerr << "Breakpoint size " << breakpoints.size() << std::endl;
            std::cerr << "Color size " << colors.size() << std::endl;
            return 1;
        }

        ElVis::VolumeRenderingIntegrationType integrationType = static_cast<ElVis::VolumeRenderingIntegrationType>(vm[integrationTypeLabel].as<int>());

        double h = .1;
        if( vm.count(hLabel) == 1 )
        {
            h = vm[hLabel].as<double>();
        }

        double epsilon = .001;
        if( vm.count(epsilonLabel) == 1 )
        {
            epsilon = vm[epsilonLabel].as<double>();
        }

        bool trackNumSamples = false;
        if( vm.count(trackNumSamplesLabel) == 1 )
        {
            trackNumSamples = (vm[trackNumSamplesLabel].as<int>() == 1);
        }

        bool renderIntegrationType = false;
        if( vm.count(renderIntegrationTypeLabel) == 1 )
        {
            renderIntegrationType = (vm[renderIntegrationTypeLabel].as<int>() == 1);
        }

        bool enableEmptySpaceSkipping = true;
        if( vm.count(emptySpaceSkippingLabel) == 1 )
        {
            enableEmptySpaceSkipping = (vm[emptySpaceSkippingLabel].as<int>() == 1);
        }

        boost::shared_ptr<ElVis::VolumeRenderingModule> m_volumeRenderingModule(new ElVis::VolumeRenderingModule());
        m_volumeRenderingModule->SetIntegrationType(integrationType);
        m_volumeRenderingModule->SetCompositingStepSize(h);
        m_volumeRenderingModule->SetEpsilon(epsilon);

        m_volumeRenderingModule->SetRenderIntegrationType(renderIntegrationType);
        m_volumeRenderingModule->SetEnableEmptySpaceSkipping(enableEmptySpaceSkipping);

        m_volumeRenderingModule->SetTrackNumberOfSamples(trackNumSamples);

        // Setup the transfer function.
        boost::shared_ptr<ElVis::HostTransferFunction> transferFunction = m_volumeRenderingModule->GetTransferFunction();
        for(unsigned int i = 0; i < breakpoints.size(); ++ i)
        {
            ElVis::Color c(colors[i*4], colors[i*4+1], colors[i*4+2], colors[i*4+3]);
            transferFunction->SetBreakpoint(breakpoints[i], c);
        }

        view->AddRenderModule(m_volumeRenderingModule);
    }

    boost::shared_ptr<ElVis::LightingModule> lighting(new ElVis::LightingModule());
    view->AddRenderModule(lighting);


    view->SetScene(scene);
    view->Resize(width, height);


    // Don't time to take care of initialization artifacts.
    view->Draw();


    double* times = new double[numTests-1];
    for(unsigned int testNum = 1; testNum < numTests; ++testNum)
    {
        // Repeated redraws will do nothing if we don't signal that the view has changed in some way.
        view->OnSceneViewChanged(*view);
        ElVis::Timer t = view->Draw();
        times[testNum-1] = t.TimePerTest(1);
    }

    view->WriteColorBufferToFile(outFilePath.c_str());

    if( numTests > 1 )
    {
        ElVis::Stat runtimeStats(times, std::numeric_limits<ElVisFloat>::max(), numTests-1, .95);
        std::cout << "Average Time Per Run: " << runtimeStats.Mean << std::endl;
        #ifdef __GNUC__
        system("nvidia-smi");
        #endif

    }


    return 0;
}