示例#1
0
bool CropInstance::ExecuteOn( View& view )
{
   if ( !view.IsMainView() )
      return false;  // should not happen!

   if ( p_margins == 0.0 )
   {
      Console().WriteLn( "<end><cbr>&lt;* Identity *&gt;" );
      return true;
   }

   AutoViewLock lock( view );

   ImageWindow window = view.Window();
   ImageVariant image = view.Image();

   Crop C( p_margins );
   C.SetMode( static_cast<Crop::crop_mode>( p_mode ) );
   C.SetResolution( p_resolution.x, p_resolution.y );
   C.SetMetricResolution( p_metric );
   C.SetFillValues( p_fillColor );

   // Dimensions of target image
   int w0 = image.Width();
   int h0 = image.Height();

   // Dimensions of transformed image
   int width = w0, height = h0;
   C.GetNewSizes( width, height );

   if ( width < 1 || height < 1 )
      throw Error( "Crop: Invalid operation: Null target image dimensions" );

   // On 32-bit systems, make sure the resulting image requires less than 4 GB.
   if ( sizeof( void* ) == sizeof( uint32 ) )
   {
      uint64 sz = uint64( width )*uint64( height )*image.NumberOfChannels()*image.BytesPerSample();
      if ( sz > uint64( uint32_max-256 ) )
         throw Error( "Crop: Invalid operation: Target image dimensions would exceed four gigabytes" );
   }

   DeleteAstrometryMetadataAndPreviewsAndMask( window );

   Console().EnableAbort();

   StandardStatus status;
   image.SetStatusCallback( &status );

   C >> image;

   if ( p_forceResolution )
   {
      Console().WriteLn( String().Format( "Setting resolution: h:%.3lf, v:%.3lf, u:px/%s",
                                          p_resolution.x, p_resolution.y, p_metric ? "cm" : "inch" ) );
      window.SetResolution( p_resolution.x, p_resolution.y, p_metric );
   }

   return true;
}
void ImageIdentifierInterface::__ViewDrop( Control& sender, const Point& pos, const View& view, unsigned modifiers )
{
   if ( sender == GUI->Identifier_Edit )
      if ( view.IsMainView() )
      {
         instance.SetId( view.Id() );
         UpdateControls();
      }
}
bool ImageIdentifierInstance::CanExecuteOn( const View& v, pcl::String& whyNot ) const
{
   if ( !v.IsMainView() )
   {
      whyNot = "ImageIdentifier can only be executed on main views, not on previews.";
      return false;
   }

   whyNot.Clear();
   return true;
}
示例#4
0
void AnnotationInterface::DynamicMousePress( View& v, const DPoint& p, int button, unsigned buttons, unsigned modifiers )
{
   // we only use left mouse button
   if ( button != MouseButton::Left )
      return;

   if (view == 0)
   {
      // can not run on previews
      if ( !v.IsMainView() )
         throw Error( "Annotation cannot run on previews. Please select a main view." );

      view = new View( v );
   }

   // only handle events in our active view
   if (v != *view)
      return;

   // get view image window
   ImageWindow w = view->Window();

   // and image coordinates of the click point
   int imageX = RoundI(p.x);
   int imageY = RoundI(p.y);

   // if annotation is not yet placed, place it now
   if (!annotationPlaced)
   {
      // set annotation position
      instance.annotationPositionX = imageX;
      instance.annotationPositionY = imageY;
      annotationPlaced = true;

      // place leader if needed
      if (instance.annotationShowLeader)
      {
         PlaceLeaderDefault();
      }

      // update annotation rectangle
      UpdateAnnotationRect( true );

      // redraw dynamic view
      UpdateView();

      // start dragging mode until user release the mouse
      dragging = DraggingType::Text;
      w.SetDynamicCursor(move_all_XPM, 10, 10);
   }
   // if the annotation is already placed
   else
   {
      // if mouse is pressed on annotation text rectangle
      // let's start dragging
      if (textRect.Includes(imageX, imageY))
      {
         // with Ctrl, both text and leader are dragged simulaneously
         if (modifiers & KeyModifier::Control)
         {
            dragging = DraggingType::Both;
         }
         // otherwise, just text is dragged
         else
         {
            dragging = DraggingType::Text;
         }
      }
      // if mouse is pressed on annotation leader rectangle and leader is visible
      // let's start dragging
      else if (instance.annotationShowLeader && leaderRect.Includes(imageX, imageY))
      {
         // with Ctrl, both text and leader are dragged simulaneously
         if (modifiers & KeyModifier::Control)
         {
            dragging = DraggingType::Both;
         }
         // otherwise, just leader endpoint is dragged
         else
         {
            dragging = DraggingType::Leader;
         }
      }
   }

   // if any dragging is started, remember current point
   if (dragging != DraggingType::None)
   {
      lastX = imageX;
      lastY = imageY;
   }
}
示例#5
0
bool RotationInstance::ExecuteOn( View& view )
{
   if ( !view.IsMainView() )
      return false;  // should never reach this point!

   AutoViewLock lock( view );

   ImageVariant image = view.Image();

   if ( image.IsComplexSample() )
      return false;

   double degrees = Round( Deg( p_angle ), 4 );
   if ( degrees == 0 )
   {
      Console().WriteLn( "<end><cbr>&lt;* Identity *&gt;" );
      return true;
   }

   ImageWindow window = view.Window();

   window.RemoveMaskReferences();
   window.RemoveMask();
   window.DeletePreviews();

   Console().EnableAbort();

   StandardStatus status;
   image.SetStatusCallback( &status );

   if ( p_optimizeFast )
      switch ( TruncI( degrees ) )
      {
      case 90:
         Rotate90CCW() >> image;
         return true;
      case -90:
         Rotate90CW() >> image;
         return true;
      case 180:
      case -180:
         Rotate180() >> image;
         return true;
      default:
         break;
      }

   AutoPointer<PixelInterpolation> interpolation( NewInterpolation(
         p_interpolation, 1, 1, 1, 1, true, p_clampingThreshold, p_smoothness, image ) );

   Rotation T( *interpolation, p_angle );

   /*
    * On 32-bit systems, make sure the resulting image requires less than 4 GB.
    */
   if ( sizeof( void* ) == sizeof( uint32 ) )
   {
      int width = image.Width(), height = image.Height();
      T.GetNewSizes( width, height );
      uint64 sz = uint64( width )*uint64( height )*image.NumberOfChannels()*image.BytesPerSample();
      if ( sz > uint64( uint32_max-256 ) )
         throw Error( "Rotation: Invalid operation: Target image dimensions would exceed four gigabytes" );
   }

   T.SetFillValues( p_fillColor );
   T >> image;

   return true;
}
void ImageIdentifierInterface::__ViewDrag( Control& sender, const Point& pos, const View& view, unsigned modifiers, bool& wantsView )
{
   if ( sender == GUI->Identifier_Edit )
      wantsView = view.IsMainView();
}