def show_settings(self):
     """Change the UI elements to match the current display settings and other options.
     Should be called when creating the form.
     """
     self._inside_show_settings = True
     #- Display settings
     # @type param ParamReflectionDisplay
     param = display_thread.get_reflection_display_params()
     self.panel.radioPixels.SetValue(param.display_as == param.DISPLAY_AS_PIXELS)
     self.panel.radioSpheres.SetValue(param.display_as == param.DISPLAY_AS_SPHERES)
     self.panel.radioMeasured.SetValue(param.color_map == param.COLOR_BY_MEASURED)
     self.panel.radioPredicted.SetValue(param.color_map == param.COLOR_BY_PREDICTED)
     self.panel.sliderSize.SetValue(10. * param.size)
     self.panel.sliderSize.Enable(not param.automatic_size)
     self.panel.checkAutoSize.SetValue(param.automatic_size)
     
     #- Masking settings
     # @type param ParamReflectionMasking
     param = display_thread.get_reflection_masking_params()
     self.panel.choiceView.Select(param.masking_type)
     self.panel.textThreshold.SetValue( "%.2f" % param.threshold)
     #Slice settings
     self.panel.checkShowSlice.SetValue(param.use_slice)
     self.panel.sliceControl.use_slice = param.use_slice
     self.panel.sliceControl.slice_min = param.slice_min
     self.panel.sliceControl.slice_max = param.slice_max
     self._inside_show_settings = False
Example #2
0
 def onPanel3DSize(self, event):
     #The 3d view is resized
     if not self.controller.in_volume_mode():
         param = display_thread.get_reflection_display_params()
         #Only redraw for automatic pixel size
         if param.automatic_size and param.display_as == model.experiment.ParamReflectionDisplay.DISPLAY_AS_PIXELS:
             self.controller.auto_adjust_pixel_size()
     event.Skip()
Example #3
0
 def auto_adjust_pixel_size(self):
     """Change the size of the pixels drawn to make them look good on screen.
     Call this when the window is resized or when the # of points plotted changes."""
     #Figure out a good pixel size
     (w, h) = self.scene.render_window.size
     diag = np.sqrt(w * w + h * h)
     display = display_thread.get_reflection_display_params()
     pixel_size = diag / 300.  # * (display.size / 5.)
     self.points_module_surface.actor.property.set(representation='points',
                                                   point_size=pixel_size)
     #Update the GUI
     self.parent_frame.tabReflections.change_displayed_size(pixel_size)
Example #4
0
 def in_pixel_mode(self):
     """Return True if we are in pixel point view mode."""
     # @type display ParamReflectionDisplay
     display = display_thread.get_reflection_display_params()
     return display.display_as == display.DISPLAY_AS_PIXELS
Example #5
0
    def update_data_points(self, *args):
        """Called when a message is received saying that the q-space
        calculation has changed.
        Will update the graphical display. TO SHOW POINTS!!
        """
        #Do we need to adjust which elements are visible?
        change_visibility = not self.in_volume_mode()

        #No GUI updates while we work
        self.scene.disable_render = True

        if change_visibility:
            #Hide the iso surface
            self.iso.visible = False
        #Ensure visibility of warning text
        self.warning_text.visible = self.warning_text_visible

        #Get the display parameters last saved.
        # @type display ParamReflectionDisplay
        display = display_thread.get_reflection_display_params()

        #Generate a new data object to make
        self.point_data_src.data = self.make_point_data()

        #Set the color map
        self.set_points_lut(display.color_map == display.COLOR_BY_PREDICTED)

        if self.in_pixel_mode():
            # ------------ Pixel View -----------------------
            self.pixel_view = True

            if change_visibility:
                #Hide the sphere view, show the points
                self.points_module_glyph.visible = False
                self.points_module_surface.visible = True

            #Change the pixel size
            if display.automatic_size:
                self.auto_adjust_pixel_size()
            else:
                #Directly use the value
                pixel_size = round(display.size)
                self.points_module_surface.actor.property.set(
                    representation='points', point_size=pixel_size)

            #Make sure the highlight cubes are okay sized
            self.resize_highlighting_cubes(self.get_best_sphere_size())

        else:
            # ------------ Sphere View -----------------------
            self.pixel_view = False

            if change_visibility:
                #Hide the points view, show the spheres
                self.points_module_glyph.visible = True
                self.points_module_surface.visible = False

            #Change the radius of the spheres
            if display.automatic_size:
                self.auto_adjust_sphere_size()
            else:
                #Use the number given
                sphere_size = display.size * self.SPHERE_SCALING
                self.points_module_glyph.glyph.glyph_source.glyph_source.radius = sphere_size
                self.resize_highlighting_cubes(sphere_size)

        # Doc says: Call this function when you change the array data in-place.
        #   This call should update the MayaVi views.
        # NOTE! Calling this from a different thread seems to crash.
        self.point_data_src.update()

        #Make sure the color scale is good
        self.fix_colorscale(self.points_module_surface)

        #This will redraw now.
        self.scene.disable_render = False

        self.point_data_needs_updating = False
Example #6
0
    def make_point_data(self):
        """Generate the point data object (type tvtk.PolyData) that is needed by the
        VTKDataSource to display the points (reflections)."""
        pd = tvtk.PolyData()
        ref_q = model.experiment.exp.reflections_q_vector
        mask = model.experiment.exp.reflections_mask

        if not isinstance(ref_q, np.ndarray):
            #No array = return an empty data set
            return pd

        assert len(
            model.experiment.exp.reflections_times_measured_with_equivalents
        ) == len(
            mask
        ), "Reflection mask and times measured should be the same length."

        #How many of the points are kept?
        num = np.sum(mask)

        #Are there more points than the configuration allows?
        num_wanted = config_gui.cfg.max_3d_points
        if num > num_wanted:
            #Adjust the mask to show only so many points
            indices = np.nonzero(mask)[0]
            #Randomize list of indices
            np.random.shuffle(indices)
            #Keep only the # wanted
            indices = indices[0:num_wanted]
            #Re-generate a smaller mask
            mask = mask.copy(
            )  #Must copy the array, otherwise we are modifying the source one
            mask &= 0
            mask[indices] = True
            #Display a warning
            self.warning_text.text = "(Points thinned down from %d to %d)" % (
                num, num_wanted)
            self.warning_text_visible = True
            #Make sure the number is correct
            num = num_wanted
        else:
            #No problem
            self.warning_text_visible = False
        self.warning_text.visible = self.warning_text_visible

        if num <= 0:
            #Nothing to show!
            return pd

        else:

            #Positions = our array of q-vectors.
            # .T = transpose
            pd.points = ref_q[:, mask].T

            #Create the vertices
            verts = np.arange(0, num, 1)
            verts.shape = (num, 1)
            pd.verts = verts
            #Put the # of times measured here as the scalar data
            param = display_thread.get_reflection_masking_params(
            )  #@type param ParamReflectionMasking
            param_display = display_thread.get_reflection_display_params(
            )  #@type param_display ParamReflectionDisplay

            if param_display.color_map == param_display.COLOR_BY_PREDICTED:
                #--- Color using the predicted measurements ---
                if param.show_equivalent_reflections:
                    #SHow times measured COUNTING equivalent (symmetrical) reflections.
                    pd.point_data.scalars = model.experiment.exp.reflections_times_measured_with_equivalents[
                        mask, :]
                else:
                    # Show only the times measured for the exact reflection
                    pd.point_data.scalars = model.experiment.exp.reflections_times_measured[
                        mask, :]

            else:
                #--- Color using the real measurements ----
                if param.show_equivalent_reflections:
                    #SHow times measured COUNTING equivalent (symmetrical) reflections.
                    pd.point_data.scalars = model.experiment.exp.reflections_times_real_measured_with_equivalents[
                        mask, :]
                else:
                    # Show only the times measured for the exact reflection
                    pd.point_data.scalars = model.experiment.exp.reflections_times_real_measured[
                        mask, :]

            pd.point_data.scalars.name = 'scalars'

        return pd