Adding command line option to mrview to set tractography colors

For some of the work we are doing, different streamlines are generated that run quite close to each other. I’d like to be able to show streamlines overlaid on b0 (and or a registered anatomic image). In the GUI, it’s easy to randomize the colors of each .tck file by selecting them all and choosing ‘Random’ from the color combo box.

However, it would be great to be able to generate screenshots programmatically with colors set from the command line. Something like:

mrview b0.nii.gz -tractography.load tract.tck -tractography.color 1,0,0 -capture.prefix ...

First off: is this possible? Secondly, any pointers on how to add this feature?

Thanks,
-dan

Hi Daniel,

This is one of many items that have been identified within mrview as being accessible from the GUI but not the command-line. In part we haven’t put the effort into covering off those functionalities not yet accessible from the command-line because we’d rather implement a more general solution that would reduce both the management and proclivity for errors in such. This would however most logically be implemented alongside a rather large mrview code overhaul, which is no trivial task.

If you’re interested in just implementing one specific functionality in order to serve a specific purpose, it’s only a matter of identifying how similar functionalities are currently implemented, and then modifying a duplicate of such for your requirement. In your case, the relevant functions are:
GUI::MRView::Tool::Tractography::add_commandline_options()
GUI::MRView::Tool::Tractography::process_commandline_option()

Cheers
Rob

Hi

Following instructions from another post, I tried to implement a solution using the following changes in src/gui/mrview/tool/tractography/tractogram.cpp :

  + Option ("tractography.colour", "Specify a manual colour for the tractogram, as three comma-separated values").allow_multiple()
            +   Argument ("R,G,B").type_sequence_float()           

and

if (opt.opt->is ("tractography.colour")) {
            try {
            
              auto values = parse_floats (opt[0]);
              if (values.size() != 3)
                throw Exception ("must provide exactly three comma-separated values to the -overlay.colour option");
              const float max_value = std::max ({ values[0], values[1], values[2] });
              if (std::min ({ values[0], values[1], values[2] }) < 0.0 || max_value > 255)
                throw Exception ("values provided to -tractogram.colour must be either between 0.0 and 1.0, or between 0 and 255");
              const float multiplier = max_value <= 1.0 ? 255.0 : 1.0;
              QColor colour (int(values[0] * multiplier), int(values[1]*multiplier), int(values[2]*multiplier));               
                           
              QModelIndexList indices = tractogram_list_view->selectionModel()->selectedIndexes(); 
              
              if (indices.size() != 1)
                  throw Exception ("-tractography.colour option requires one tractogram to be selected");
              // get pointer to tractogram:
              Tractogram* tractogram = tractogram_list_model->get_tractogram (indices[0]);
                
              //input need to be a float *  
              float colour_input[3];
                
               colour_input[0]=values[0]/255;
               colour_input[1]=values[1]/255;
               colour_input[2]=values[2]/255;
                
               // set the color
               tractogram->set_color_type (TrackColourType::Manual);
               tractogram->set_colour(colour_input);
                
               // update_color_type_gui
               colour_combobox->setCurrentIndex (3);                
               colour_button->setEnabled (true);
               colour_button->setColor (QColor (colour_input[0]*255.0f, colour_input[1]*255.0f, colour_input[2]*255.0f));
              
            
            }
            catch (Exception& e) { e.display(); }
            return true;
          }

Unfortunately , if I cannot specified different colors if I’m loading more than one tractogram.

For some reasons:

QModelIndexList indices = tractogram_list_view->selectionModel()->selectedIndexes(); 

is always set to 1

Do you know what should be changed ?

Thansk in advance
Best,
Valéry

Hi Valéry,

I recommend you set up a fork of MRtrix, push your code to your fork, and then either create a pull request or give us access to your fork so we can try it out. It would make it much easier for us to identify what the issue is if we can actually inspect it and try it out on our own systems… Would that be possible?

If you create a pull request, we can also carry on the discussion on GitHub, which is probably a better place to discuss coding-related issues.

All the best,
Donald.