I'm not sure of what I could give you ( I tried to debug with gdb but it just 
say that the application crash, I knew it -_- )

But I made a sandbox and have the same problem, the code is shorter, I'll give 
it.

I joined 3 files, the app file named paraview-crash-on-legend.cpp and my 3D 
widget.

By the way I'm open for all comment or idea of improvement or else about good 
practise.

Thanks for your fast answer !

I use :
Qt 4
Paraview 10.0-RC1.

Wertz Gil
[email protected]




> Date: Thu, 31 Mar 2011 10:40:46 -0400
> Subject: Re: [Paraview] pqColorScaleEditor crash
> From: [email protected]
> To: [email protected]
> CC: [email protected]
> 
> Gil,
> 
> If you can provide the call-stack for where you're getting the
> segfault, it will be helpful.
> 
> Utkarsh
> 
> On Thu, Mar 31, 2011 at 10:13 AM, Gil Wertz <[email protected]> wrote:
> > I'm making a program that make calculation and try to integrate some
> > Paraview stuff, every things goes fine, I have my render from the server,
> > but when I use pqColorScaleEditor, the dialog show himself, I can change
> > color depending on scale but when I check the legend checkbox, the
> > application crash and I have no idea why ...
> >
> > Part of my code :
> >
> >     void Widget3D::show_color_editor(){
> >
> >       scaleEdit = new pqColorScaleEditor(m_RenderView->getWidget());
> >       pqDataRepresentation* repr = m_input->getRepresentation(m_RenderView);
> >       scaleEdit->setRepresentation(repr);
> >       scaleEdit->show();
> >
> >     }
> >
> >     void Widget3D::createView(){
> >         if(m_server){
> >         // create a graphics window and put it in our main window
> >         this->m_RenderView = qobject_cast<pqRenderView*>(
> >           m_object_builder->createView(pqRenderView::renderViewType(),
> > m_server));
> >
> >         if(m_RenderView){
> >           m_layout_v->insertWidget(0,this->m_RenderView->getWidget());
> >         }else{
> >             //NLog::globalLog()->addError("Problem when creating a
> > RenderView.");
> >         }
> >         }else{
> >             //NLog::globalLog()->addError("Cannot create RenderView if no
> > paraview server connection is set.");
> >         }
> >
> >     }
> >
> >     void Widget3D::showRender()
> >     {
> >         if(m_source){
> >
> >             m_input = m_source;//m_filter2;
> >
> >
> > m_object_builder->createDataRepresentation(m_input->getOutputPort(0),
> > this->m_RenderView);
> >
> >             changeStyle();
> >
> >             pqDataRepresentation* repr =
> > m_input->getRepresentation(m_RenderView);
> >
> >
> > this->m_color->setRepresentation(m_input->getRepresentation(m_RenderView));
> >
> >
> > //this->scaleEdit->setRepresentation(m_input->getRepresentation(m_RenderView));
> >
> >             qDebug() << repr->getLookupTable();
> >             //m_RenderView->get
> >             qDebug() << repr->getLookupTableProxy();
> >
> >             // zoom to object
> >             this->m_RenderView->resetCamera();
> >             // make sure we update
> >             this->m_RenderView->render();
> >
> >         }else{
> >             //NLog::globalLog()->addError("There is no file to render.");
> >         }
> >     }
> >
> >     Widget3D::Widget3D(QWidget *parent) :
> >             QWidget(parent)
> >     {
> >         // automatically make a server connection
> >         m_core = pqApplicationCore::instance();
> >         m_object_builder = m_core->getObjectBuilder();
> >
> >         // Register ParaView interfaces.
> >         m_plugin_manager = m_core->getPluginManager();
> >
> >         // adds support for standard paraview views.
> >         m_plugin_manager->addInterface(new
> > pqStandardViewModules(m_plugin_manager));
> >
> >     createView();
> >
> >         showRender();
> >
> >
> > connect(m_show_color_palet,SIGNAL(released()),this,SLOT(show_color_editor()));
> >
> >     }
> >
> >
> >
> > You'll notice that I use client - server paraview architecture. What is
> > strange is that I have no problem seting color on my mesh but the legend
> > make the application crash.
> >
> > I tryed different things like :
> >       scaleEdit = new pqColorScaleEditor(m_RenderView->getWidget());
> >       scaleEdit->show();
> >      => it show me that there is no map ta set the legend... So I think it
> > found the map
> >
> > Maybe the problem is that the rendering is made in server side, but I did
> > not have problems with "pqDisplayColorWidget" that also use
> > pqDataRepresentation.
> >
> >
> > Thanks for any idea, if you need the full code I can provide it.
> >
> > ________________________________
> >
> > Wertz Gil
> >
> > [email protected]
> >
> > ________________________________
> >
> >
> > _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Please keep messages on-topic and check the ParaView Wiki at:
> > http://paraview.org/Wiki/ParaView
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.paraview.org/mailman/listinfo/paraview
> >
> >
                                          
#include <QApplication>
#include <pqApplicationCore.h>
#include "Widget3D.hpp"

int main(int argc, char * argv[])
{
  QApplication app(argc, argv);

  pqApplicationCore pc(argc, argv);

  Widget3D * w = new  Widget3D();

  w->show();

  return app.exec();
}
// Qt headers
#include <QHBoxLayout>
#include <QLabel>
#include <QDialog>
#include <QIntValidator>
#include <QMap>
#include <QList>
#include <QDebug>
#include <QFileDialog>

// ParaView header
#include "vtkSMPropertyHelper.h"
#include "pqDataRepresentation.h"
#include "vtkSmartPointer.h"
#include "vtkLookupTable.h"
#include "vtkUnsignedCharArray.h"
#include "vtkPolyData.h"
#include "vtkSMDocumentation.h"
#include "vtkPVDataInformation.h"
#include "pqProgressManager.h"
#include "pqTimeKeeper.h"
#include "vtkPNGWriter.h"
#include "vtkWindowToImageFilter.h"
#include "pqCameraToolbar.h"


// header
#include "Widget3D.hpp"

////////////////////////////////////////////////////////////////////////////////

    Widget3D::Widget3D(QWidget *parent) :
            QWidget(parent)
    {
        // automatically make a server connection
        m_core = pqApplicationCore::instance();
        m_object_builder = m_core->getObjectBuilder();

        // Register ParaView interfaces.
        m_plugin_manager = m_core->getPluginManager();

        // adds support for standard paraview views.
        m_plugin_manager->addInterface(new pqStandardViewModules(m_plugin_manager));

        //define timeout of connection process
//        pqProgressManager * m_progress_manager = m_core->getProgressManager();
//        m_progress_manager->setEnableProgress(false);


        //pqServerManagerModel* sm = m_core->getServerManagerModel();
        m_color = new pqDisplayColorWidget(this);

        //pqCameraToolbar * camtool = new pqCameraToolbar("camTool",this);

        //camDia = new pqCameraDialog(camtool);

        m_layout_v = new QVBoxLayout();

        m_layout_option = new QHBoxLayout();
        m_layout_option2 = new QHBoxLayout();

        m_connect_to_server_button = new QPushButton("Connect",this);

        m_load_file = new QPushButton("Load File",this);

        m_load_file->setEnabled(false);

        m_set_rotation_center = new QPushButton("Fix Center Rotation",this);

        m_screen_shot = new QPushButton("Screen Shot",this);

        m_reset_camera = new QPushButton("Reset Camera",this);

        m_show_color_palet = new QPushButton("Show Color Palet",this);

        m_style = new QComboBox(this);
        m_style->addItem("Point",0);
        m_style->addItem("Wireframe",1);
        m_style->addItem("Surface",2);
        m_style->addItem("Outline",3);
        m_style->addItem("Volume",4);
        m_style->addItem("Surface with edges",5);
        m_style->setEditable(false);
        m_style->setCurrentIndex(2);
        m_style->setEnabled(false);

        m_preDefined_rotation = new QComboBox(this);
        m_preDefined_rotation->addItem("+X",0);
        m_preDefined_rotation->addItem("+Y",1);
        m_preDefined_rotation->addItem("+Z",2);
        m_preDefined_rotation->addItem("-X",3);
        m_preDefined_rotation->addItem("-Y",4);
        m_preDefined_rotation->addItem("-Z",5);
        m_preDefined_rotation->setEditable(false);

        this->setLayout(m_layout_v);

        m_server = m_object_builder->createServer(pqServerResource("builtin:"));
        m_server->setHeartBeatTimeoutSetting(10);

        if(m_server){
            createView();
        }else{

        }


        //disposition
        this->m_connect_to_server_button->setMaximumWidth(100);
        this->m_load_file->setMaximumWidth(100);
        this->m_style->setMaximumWidth(150);
        this->m_set_rotation_center->setMaximumWidth(150);
        this->m_color->setMaximumWidth(250);


        //m_layout_option->addWidget(camtool);
        m_layout_option->addWidget(this->m_connect_to_server_button);
        m_layout_option->addWidget(this->m_load_file);
        m_layout_option->addWidget(this->m_style);
        m_layout_option->addWidget(this->m_set_rotation_center);
        m_layout_option->addWidget(this->m_color);
        m_layout_option2->addWidget(this->m_reset_camera);
        m_layout_option2->addWidget(this->m_screen_shot);
        m_layout_option2->addWidget(this->m_preDefined_rotation);
        m_layout_option2->addWidget(this->m_show_color_palet);


        m_layout_v->addLayout(this->m_layout_option);
        m_layout_v->addLayout(this->m_layout_option2);

        //connect
        connect(m_connect_to_server_button,SIGNAL(released()),this,SLOT(showConnectDialog()));
        connect(m_load_file,SIGNAL(released()),this,SLOT(showLoadFileDialog()));
        connect(m_style,SIGNAL(currentIndexChanged (int)),this,SLOT(changeStyle()));
        connect(m_set_rotation_center,SIGNAL(released()),this,SLOT(set_rotation_center()));
        connect(m_preDefined_rotation,SIGNAL(activated(int)),this,SLOT(set_rotation(int)));
        connect(m_screen_shot,SIGNAL(released()),this,SLOT(take_screen_shot()));
        connect(m_reset_camera,SIGNAL(released()),this,SLOT(reset_camera()));
        connect(m_show_color_palet,SIGNAL(released()),this,SLOT(show_color_editor()));
    }

    void Widget3D::connectToServer()
    {

        QString given_host = m_host_line->text();
        QString port = m_port_line->text();

            QString host = "cs://";
            host += given_host;
            host += ":";
            host += port;

            if(m_server)
                m_object_builder->removeServer(m_server);

            m_server = m_object_builder->createServer(pqServerResource(host));


            if(m_server && m_server->isRemote()){;
                this->m_connect_to_server_button->setText("Disconnect");
                m_load_file->setEnabled(true);
                disconnect(m_connect_to_server_button,SIGNAL(released()),this,SLOT(showConnectDialog()));
                connect(m_connect_to_server_button,SIGNAL(clicked()),this,SLOT(disconnectFromServer()));
                createView();
            }else{
                m_server = m_object_builder->createServer(pqServerResource("builtin:"));
                createView();
            }

    }

    void Widget3D::openFile()
    {

        if(m_source)
            m_object_builder->destroy(m_source);

        QString given_file = m_Path_File_line->text();

        if(m_server && m_server->isRemote()){
        //detecting extention and launching correct reader

          QString extention = given_file.section('.',-1);

        //create reader depending on file
          if(!extention.compare("vtk")){
              m_source = m_object_builder->createReader("sources", "LegacyVTKFileReader",QStringList(given_file), m_server);
          }
          if(!extention.compare("ex2")){
              m_source = m_object_builder->createReader("sources", "ExodusIIReader",QStringList(given_file), m_server);
          }

          if(m_source){

              vtkSMSourceProxy::SafeDownCast(m_source->getProxy())->UpdatePipeline();

              if(m_source && m_server){
                  m_style->setEnabled(true);
                  showRender();
              }
          }else{
              m_style->setEnabled(false);
          }
      }else{
          m_style->setEnabled(false);
      }
    }

    void Widget3D::showRender()
    {
        if(m_source){

            m_input = m_source;//m_filter2;

            m_object_builder->createDataRepresentation(m_input->getOutputPort(0), this->m_RenderView);

            changeStyle();

            pqDataRepresentation* repr = m_input->getRepresentation(m_RenderView);

            this->m_color->setRepresentation(m_input->getRepresentation(m_RenderView));

            //this->scaleEdit->setRepresentation(m_input->getRepresentation(m_RenderView));

            // zoom to object
            this->m_RenderView->resetCamera();
            // make sure we update
            this->m_RenderView->render();

        }else{

        }
    }

    void Widget3D::createView(){
        if(m_server){
        // create a graphics window and put it in our main window
        this->m_RenderView = qobject_cast<pqRenderView*>(
          m_object_builder->createView(pqRenderView::renderViewType(), m_server));

        if(m_RenderView){
          m_layout_v->insertWidget(0,this->m_RenderView->getWidget());
        }else{
        }
        }else{
        }

    }

    void Widget3D::disconnectFromServer(){

        if(m_source)
            m_object_builder->destroySources(m_server);

        if(m_server)
            m_object_builder->removeServer(m_server);

        if(m_RenderView)
            m_object_builder->destroy(m_RenderView);

        m_server = m_object_builder->createServer(pqServerResource("builtin:"));

        createView();

        m_style->setEnabled(false);

        this->m_connect_to_server_button->setText("Connect");

        m_load_file->setEnabled(false);
        disconnect(m_connect_to_server_button,SIGNAL(clicked()),this,SLOT(disconnectFromServer()));
        connect(m_connect_to_server_button,SIGNAL(released()),this,SLOT(showConnectDialog()));
    }

    void Widget3D::showLoadFileDialog(){
        //the popup dialog box
        QPointer<QDialog> loadFileDialog = new QDialog(this);

        //adding Exit and Connect button
        QPointer<QPushButton> btn_load = new QPushButton("Load", loadFileDialog);
        QPointer<QPushButton> btn_exit = new QPushButton("Exit", loadFileDialog);

        // line edit
        m_Path_File_line = new QLineEdit("skeleton.vtk",this);

        // labels
        QPointer<QLabel> path_label = new QLabel("File Path");

        // popup layout
        QPointer<QVBoxLayout> vertical_popup_layout = new QVBoxLayout();
        QPointer<QHBoxLayout> horisontal_path_layout = new QHBoxLayout();
        QPointer<QHBoxLayout> horisontal_button_layout = new QHBoxLayout();

        horisontal_path_layout->addWidget(path_label);
        horisontal_path_layout->addWidget(m_Path_File_line);

        horisontal_button_layout->addWidget(btn_load);
        horisontal_button_layout->addWidget(btn_exit);

        vertical_popup_layout->addLayout(horisontal_path_layout);
        vertical_popup_layout->addLayout(horisontal_button_layout);

        loadFileDialog->setLayout(vertical_popup_layout);

        //connect them to their actions
        connect(btn_exit, SIGNAL(released()),loadFileDialog,SLOT(close()));
        connect(btn_load, SIGNAL(released()),this,SLOT(openFile()));
        connect(btn_load, SIGNAL(released()),loadFileDialog,SLOT(close()));

        loadFileDialog->resize(350,100);
        loadFileDialog->setModal(true);
        loadFileDialog->show();
    }

    void Widget3D::showConnectDialog(){
        //the popup dialog box
        QPointer<QDialog> connectFileDialog = new QDialog(this);

        //adding Exit and Connect button
        QPointer<QPushButton> btn_connect = new QPushButton("Connect", connectFileDialog);
        QPointer<QPushButton> btn_exit = new QPushButton("Exit", connectFileDialog);

        // line edit
        m_port_line = new QLineEdit("11111",this);
        m_port_line->setValidator(new  QIntValidator(nullptr));
        m_host_line = new QLineEdit("10.120.0.24",this);

        // labels
        QPointer<QLabel> port_label = new QLabel("port");
        QPointer<QLabel> host_label = new QLabel("host");

        // popup layout
        QPointer<QVBoxLayout> vertical_popup_layout = new QVBoxLayout();
        QPointer<QHBoxLayout> horisontal_host_layout = new QHBoxLayout();
        QPointer<QHBoxLayout> horisontal_port_layout = new QHBoxLayout();
        QPointer<QHBoxLayout> horisontal_button_layout = new QHBoxLayout();

        horisontal_host_layout->addWidget(host_label);
        horisontal_host_layout->addWidget(m_host_line);

        horisontal_port_layout->addWidget(port_label);
        horisontal_port_layout->addWidget(m_port_line);

        horisontal_button_layout->addWidget(btn_connect);
        horisontal_button_layout->addWidget(btn_exit);

        vertical_popup_layout->addLayout(horisontal_host_layout);
        vertical_popup_layout->addLayout(horisontal_port_layout);
        vertical_popup_layout->addLayout(horisontal_button_layout);

        connectFileDialog->setLayout(vertical_popup_layout);

        //connect them to their actions
        connect(btn_exit, SIGNAL(released()),connectFileDialog,SLOT(close()));
        connect(btn_connect, SIGNAL(released()),this,SLOT(connectToServer()));
        connect(btn_connect, SIGNAL(released()),connectFileDialog,SLOT(close()));

        connectFileDialog->resize(100,80);
        connectFileDialog->setModal(true);
        connectFileDialog->show();
    }

    void Widget3D::addFilter(){

    }

    void Widget3D::changeStyle(){
        pqDataRepresentation* repr = m_input->getRepresentation(m_RenderView);
        if (repr)
          {
          vtkSMPropertyHelper(repr->getProxy(), "Representation").Set(m_style->currentIndex());
          repr->getProxy()->UpdateVTKObjects();
          m_RenderView->forceRender();
          }
    }

    void Widget3D::set_rotation_center(){
      m_RenderView->resetCenterOfRotation();
      m_RenderView->forceRender();
    }

    void Widget3D::set_rotation(int value){

      switch (value)
        {

      case 0://RESET_POSITIVE_X:
        m_RenderView->resetViewDirection(1, 0, 0, 0, 0, 1);
        break;

      case 1://RESET_POSITIVE_Y:
        m_RenderView->resetViewDirection(0, 1, 0, 0, 0, 1);
        break;

      case 2://RESET_POSITIVE_Z:
        m_RenderView->resetViewDirection(0, 0, 1, 0, 1, 0);
        break;

      case 3://RESET_NEGATIVE_X:
        m_RenderView->resetViewDirection(-1, 0, 0, 0, 0, 1);
        break;

      case 4://RESET_NEGATIVE_Y:
        m_RenderView->resetViewDirection(0, -1, 0, 0, 0, 1);
        break;
      case 5://RESET_NEGATIVE_Z:
        m_RenderView->resetViewDirection(0, 0, -1, 0, 1, 0);
        break;
        }
    }

    void Widget3D::take_screen_shot(){

      // Screenshot
        //default file name
        QString file_name = "coolfluid3DScreenShot.png";

        //getting the file name and path for saving file
        file_name = QFileDialog::getSaveFileName(
            this, "Export File Name", file_name,
            "png Images (*.png)");

        if ( !file_name.isEmpty() )
        {
          vtkPNGWriter *writer = vtkPNGWriter::New();
          writer->SetInput(m_RenderView->captureImage(0));
          writer->SetFileName(file_name.toStdString().c_str());
          writer->SetFileDimensionality(3);
          writer->Write();

        }
    }

    void Widget3D::reset_camera(){
      m_RenderView->resetCamera();
    }

    void Widget3D::show_color_editor(){

      scaleEdit = new pqColorScaleEditor(m_RenderView->getWidget());
      pqDataRepresentation* repr = m_input->getRepresentation(m_RenderView);
      scaleEdit->setRepresentation(repr);
      scaleEdit->show();

    }
#ifndef Widget3D_hpp
#define Widget3D_hpp

// Qt headers
#include <QVBoxLayout>
#include <QMainWindow>
#include <QPointer>
#include <QPushButton>
#include <QLineEdit>
#include <QComboBox>
#include <QHBoxLayout>

// ParaView header
#include "vtkSMSourceProxy.h"
#include "pqApplicationCore.h"
#include "pqObjectBuilder.h"
#include "pqPipelineSource.h"
#include "pqPluginManager.h"
#include "pqServer.h"
#include "pqStandardViewModules.h"
#include "pqRenderView.h"
#include "pqOutputPort.h"
#include "pqDisplayColorWidget.h"
#include "pqDisplayProxyEditor.h"
#include "pqCameraDialog.h"
#include "pqColorScaleEditor.h"

////////////////////////////////////////////////////////////////////////////////

class Widget3D : public QWidget
{
  Q_OBJECT

public: //function

  /// Light Constructor
  /// @param parent Parent QWdiget.
  Widget3D(QWidget *parent = 0);

private : //function

    /// Show the render of a file if the server connection is set and a the file exist
    void showRender();

    /// Create a view from server
    void createView();

    /// Add a filter
    void addFilter();


private slots: //slots

  /// Ask connection options and try to connect to a certain host & port
  void connectToServer();

  /// Ask connection options and try to connect to a certain host & port
  void disconnectFromServer();

  /// Create a reader for the defined PATH file on the server side ( .vtk or .ex2 )
  void openFile();

  /// Show a dialog window that ask for a path file
  void showLoadFileDialog();

  /// Show a dialog window that ask for an host and port
  void showConnectDialog();

  /// Change Style
  void changeStyle();

  /// Set the rotation center
  void set_rotation_center();

  /// Set the current rotation
  void set_rotation(int value);

  /// Take a screen shot of the current view
  void take_screen_shot();

  /// reset the camera
  void reset_camera();

  void show_color_editor();

private: //data

  /// Initialising Application Core that manage all vtk and paraview Objects.
  QPointer<pqApplicationCore> m_core;

  /// Object Builder create Object on server side and a ghost on client side.
  QPointer<pqObjectBuilder> m_object_builder;

  /// Server connection
  QPointer<pqServer> m_server;

  /// Plugin manger that give acces to advenced object and view
  QPointer<pqPluginManager> m_plugin_manager;

  /// Layout of this widget
  QPointer<QVBoxLayout> m_layout_v;

  /// Layout of this widget
  QPointer<QHBoxLayout> m_layout_option;

  /// Layout of this widget
  QPointer<QHBoxLayout> m_layout_option2;

  /// Button that show Server Connection dialog
  QPointer<QPushButton> m_connect_to_server_button;

  /// Button that show Server Load File dialog
  QPointer<QPushButton> m_load_file;

  /// Button that reset center of rotation
  QPointer<QPushButton> m_set_rotation_center;

  /// Button make a screen shot
  QPointer<QPushButton> m_screen_shot;

  /// Button make a screen shot
  QPointer<QPushButton> m_reset_camera;

  /// Button make a screen shot
  QPointer<QPushButton> m_show_color_palet;

  /// ComboBox of dataRepresentation style
  QPointer<QComboBox> m_style;

  /// Combobox of predefined rotation set
  QPointer<QComboBox> m_preDefined_rotation;

  /// Source Pipeline is a flow from the source readed to show actor.
  QPointer<pqPipelineSource> m_source;

  /// render window input Pipeline.
  QPointer<pqPipelineSource> m_input;

  /// View where the render is shown
  QPointer<pqRenderView> m_RenderView;

  /// Server Port LineEdit
  QPointer<QLineEdit> m_port_line;

  /// Server Host LineEdit
  QPointer<QLineEdit> m_host_line;

  /// Server File Path LineEdit
  QPointer<QLineEdit> m_Path_File_line;

  pqDisplayColorWidget * m_color;

  pqDisplayProxyEditor * m_disp_pan;

  pqCameraDialog * camDia;

  pqColorScaleEditor * scaleEdit;

};


////////////////////////////////////////////////////////////////////////////////

#endif // Widget3D_hpp
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Follow this link to subscribe/unsubscribe:
http://www.paraview.org/mailman/listinfo/paraview

Reply via email to