bool ConvertToRGBColorInstance::ExecuteOn( View& view ) { ImageWindow window = view.Window(); Array<ImageWindow> windows = ImageWindow::AllWindows(); for ( size_type i = 0; i < windows.Length(); ++i ) if ( windows[i].Mask() == window && !windows[i].MainView().IsColor() ) windows[i].RemoveMask(); AutoViewLock lock( view ); ImageVariant image = view.Image(); StandardStatus status; image.SetStatusCallback( &status ); Console().EnableAbort(); image.SetColorSpace( ColorSpace::RGB ); return true; }
void ColorCalibrationInterface::__Click( Button& sender, bool checked ) { if ( sender == GUI->WhiteReferenceView_ToolButton ) { ViewSelectionDialog d( instance.whiteReferenceViewId ); if ( d.Execute() == StdDialogCode::Ok ) { instance.whiteReferenceViewId = d.Id(); GUI->WhiteReferenceView_Edit.SetText( WHITE_REFERENCE_ID ); } } else if ( sender == GUI->BackgroundReferenceView_ToolButton ) { ViewSelectionDialog d( instance.backgroundReferenceViewId ); if ( d.Execute() == StdDialogCode::Ok ) { instance.backgroundReferenceViewId = d.Id(); GUI->BackgroundReferenceView_Edit.SetText( BACKGROUND_REFERENCE_ID ); } } else if ( sender == GUI->OutputWhiteReferenceMask_CheckBox ) instance.outputWhiteReferenceMask = checked; else if ( sender == GUI->OutputBackgroundReferenceMask_CheckBox ) instance.outputBackgroundReferenceMask = checked; else if ( sender == GUI->WhiteROISelectPreview_Button ) { PreviewSelectionDialog d; if ( d.Execute() ) if ( !d.Id().IsEmpty() ) { View view = View::ViewById( d.Id() ); if ( !view.IsNull() ) { instance.whiteROI = view.Window().PreviewRect( view.Id() ); UpdateControls(); } } } else if ( sender == GUI->BackgroundROISelectPreview_Button ) { PreviewSelectionDialog d; if ( d.Execute() ) if ( !d.Id().IsEmpty() ) { View view = View::ViewById( d.Id() ); if ( !view.IsNull() ) { instance.backgroundROI = view.Window().PreviewRect( view.Id() ); UpdateControls(); } } } }
void NewImageInterface::UpdateReadout( const View& v, const DPoint&, double R, double G, double B, double A ) { if ( GUI != 0 && IsVisible() ) { if ( ISCOLOR || !v.IsColor() ) { instance.v0 = R; instance.v1 = G; instance.v2 = B; } else { RGBColorSystem rgb; v.Window().GetRGBWS( rgb ); instance.v0 = instance.v1 = instance.v2 = rgb.Lightness( R, G, B ); } GUI->V0_NumericControl.SetValue( instance.v0 ); GUI->V1_NumericControl.SetValue( instance.v1 ); GUI->V2_NumericControl.SetValue( instance.v2 ); if ( HASALPHA ) { instance.va = A; GUI->VA_NumericControl.SetValue( instance.va ); } GUI->ColorSample_Control.Update(); } }
bool FluxCalibrationInstance::CanExecuteOn( const View& view, pcl::String& whyNot ) const { if ( view.Image().IsComplexSample() ) { whyNot = "FluxCalibration cannot be executed on complex images."; return false; } if ( view.Image()->IsColor() ) { whyNot = "FluxCalibration cannot be executed on color images."; return false; } FITSKeywordArray inputKeywords; view.Window().GetKeywords( inputKeywords ); if ( FluxCalibrationEngine::KeywordExists( inputKeywords, "FLXMIN" ) || FluxCalibrationEngine::KeywordExists( inputKeywords, "FLXRANGE" ) || FluxCalibrationEngine::KeywordExists( inputKeywords, "FLX2DN" ) ) { whyNot = "FluxCalibration cannot be executed on an already flux-calibrated image."; return false; } whyNot.Clear(); return true; }
bool CropInstance::ExecuteOn( View& view ) { if ( !view.IsMainView() ) return false; // should not happen! if ( p_margins == 0.0 ) { Console().WriteLn( "<end><cbr><* Identity *>" ); 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 AnnotationInterface::Execute() { // can't execute if annotation is not placed in a valid view if (view == 0 || !annotationPlaced) { MessageBox mb("Can't execute. Use left mouse button to place annotation on the image first.", "Not executed", StdIcon::Information); mb.Execute(); return; } // check mask. if enabled, offer user to temporarily disable it bool disableMask = false; if ( view->Window().IsMaskEnabled() && !view->Window().Mask().IsNull() ) { MessageBox mb("The view has a mask enabled. Mask will probably interfere with the annotation rendering.<br/>" "Do you want to temporarily disable the mask?", "Mask Enabled", StdIcon::Question, StdButton::Yes, StdButton::No, StdButton::Cancel, 0, 2); MessageBox::std_button result = mb.Execute(); if (result == StdButton::Cancel) return; disableMask = result == StdButton::Yes; } // Obtain local working references to the target view and window. View v = *view; ImageWindow w = v.Window(); // Reset reference to the target view in the dynamic interface. This // prevents inconsistent behavior during execution. delete view, view = 0; ClearBitmaps(); // Since active dynamic targets cannot be modified, we have to remove our // target view from the dynamic targets set before attempting to process. v.RemoveFromDynamicTargets(); // Ensure that our target view is selected as the current view. w.BringToFront(); w.SelectView( v ); // Disable mask if required if ( disableMask ) w.EnableMask( false ); // Execute the instance on the target window. instance.LaunchOn( w ); // Re-enable mask if required if ( disableMask ) w.EnableMask( true ); // keep parameters but reset state annotationPlaced = false; leaderPlaced = false; }
bool RGBWorkingSpaceInstance::ExecuteOn( View& view ) { RGBWorkingSpaceInstance t( *this ); t.NormalizeLuminanceCoefficients(); RGBColorSystem rgbws( t.gamma, t.sRGB != 0, t.x, t.y, t.Y ); view.Window().SetRGBWS( rgbws ); return true; }
void HDRCompositionInterface::__FittingRegion_Click( Button& sender, bool checked ) { if ( sender == GUI->SelectPreview_Button ) { PreviewSelectionDialog d; if ( d.Execute() ) if ( !d.Id().IsEmpty() ) { View view = View::ViewById( d.Id() ); if ( !view.IsNull() ) { instance.fittingRect = view.Window().PreviewRect( view.Id() ); UpdateFittingRegionControls(); } } } }
void BinarizeInterface::UpdateReadout( const View& v, const DPoint&, double R, double G, double B, double /*A*/ ) { if ( GUI != 0 && IsVisible() ) { if ( instance.isGlobal ) { RGBColorSystem rgbws; v.Window().GetRGBWS( rgbws ); instance.level[0] = instance.level[1] = instance.level[2] = rgbws.Lightness( R, G, B ); } else { instance.level[0] = R; instance.level[1] = G; instance.level[2] = B; } UpdateControls(); if ( !RealTimePreview::IsUpdating() ) RealTimePreview::Update(); } }
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><* Identity *>" ); 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; }
static void Apply( GenericImage<P>& img, const View& view, const FluxCalibrationInstance& instance ) { FITSKeywordArray inputKeywords; view.Window().GetKeywords( inputKeywords ); if ( KeywordExists( inputKeywords, "FLXMIN" ) || KeywordExists( inputKeywords, "FLXRANGE" ) || KeywordExists( inputKeywords, "FLX2DN" ) ) { throw Error( "Already calibrated image" ); } if ( img.IsColor() ) throw Error( "Can't calibrate a color image" ); float Wc = instance.p_wavelength.GetValue( inputKeywords ); float Tr = Max( 1.0F, instance.p_transmissivity.GetValue( inputKeywords ) ); float Delta = instance.p_filterWidth.GetValue( inputKeywords ); float Ap = instance.p_aperture.GetValue( inputKeywords ) / 10; // mm -> cm float Cobs = Max( 0.0F, instance.p_centralObstruction.GetValue( inputKeywords ) ) / 10; // mm -> cm float ExpT = instance.p_exposureTime.GetValue( inputKeywords ); float AtmE = Max( 0.0F, instance.p_atmosphericExtinction.GetValue( inputKeywords ) ); float G = Max( 1.0F, instance.p_sensorGain.GetValue( inputKeywords ) ); float QEff = Max( 1.0F, instance.p_quantumEfficiency.GetValue( inputKeywords ) ); if ( Wc <= 0 ) throw Error( "Invalid filter wavelength" ); if ( Tr <= 0 || Tr > 1 ) throw Error( "Invalid filter transmissivity" ); if ( Delta <= 0 ) throw Error( "Invalid filter width" ); if ( Ap <= 0 ) throw Error( "Invalid aperture" ); if ( Cobs < 0 || Cobs >= Ap ) throw Error( "Invalid central obstruction area" ); if ( ExpT <= 0 ) throw Error( "Invalid exposure time" ); if ( AtmE < 0 || AtmE >= 1 ) throw Error( "Invalid atmospheric extinction" ); if ( G <= 0 ) throw Error( "Invalid sensor gain" ); if ( QEff <= 0 || QEff > 1 ) throw Error( "Invalid quantum efficiency" ); FITSKeywordArray keywords; float pedestal = 0; bool foundPedestal = false; for ( FITSKeywordArray::const_iterator i = inputKeywords.Begin(); i != inputKeywords.End(); ++i ) if ( i->name == "PEDESTAL" ) { if ( i->value.TryToFloat( pedestal ) ) foundPedestal = true; pedestal /= 65535; // 2^16-1 maximum value of a 16bit CCD. } else keywords.Add( *i ); if ( foundPedestal ) Console().NoteLn( "<end><cbr><br>* FluxCalibration: PEDESTAL keyword found: " + view.FullId() ); // double F = Wc * inv_ch * (1 - Tr) * Delta * Ap * Cobs * ExpT * AtmE * G * QEff; double F = Wc * inv_ch * (1 - AtmE) * Delta * ( Const<double>::pi() / 4 * ( Ap*Ap - Cobs*Cobs ) ) * ExpT * Tr * G * QEff; size_type N = img.NumberOfPixels(); typename P::sample* f = img.PixelData( 0 ); const typename P::sample* fN = f + N; double flxMin = DBL_MAX; double flxMax = 0; for ( ; f < fN; ++f, ++img.Status() ) { double I; P::FromSample( I, *f ); I = (I - pedestal)/F; *f = P::ToSample( I ); if ( I < flxMin ) flxMin = I; if ( I > flxMax ) flxMax = I; } img.Rescale(); keywords.Add( FITSHeaderKeyword( "FLXMIN", IsoString().Format( "%.8e", flxMin ), "" ) ); keywords.Add( FITSHeaderKeyword( "FLXRANGE", IsoString().Format( "%.8e", flxMax - flxMin ), "FLXRANGE*pixel_value + FLXMIN = erg/cm^2/s/nm" ) ); keywords.Add( FITSHeaderKeyword( "FLX2DN", IsoString().Format( "%.8e", F*65535 ), "(FLXRANGE*pixel_value + FLXMIN)*FLX2DN = DN" ) ); view.Window().SetKeywords( keywords ); }
void B3EInterface::__Clicked( Button& sender, bool checked ) { if ( sender == GUI->InputImage1_ToolButton ) { ViewSelectionDialog d( instance.p_inputView[0].id ); d.SetWindowTitle( "Select First Input Image" ); if ( d.Execute() ) instance.p_inputView[0].id = d.Id(); GUI->InputImage1_Edit.SetText( instance.p_inputView[0].id ); } else if ( sender == GUI->InputImage2_ToolButton ) { ViewSelectionDialog d( instance.p_inputView[1].id ); d.SetWindowTitle( "Select Second Input Image" ); if ( d.Execute() ) instance.p_inputView[1].id = d.Id(); GUI->InputImage2_Edit.SetText( instance.p_inputView[1].id ); } else if ( sender == GUI->OutOfRangeMask_CheckBox ) { instance.p_outOfRangeMask = checked; } else if ( sender == GUI->BackgroundReferenceView1_ToolButton ) { ViewSelectionDialog d( instance.p_inputView[0].backgroundReferenceViewId ); d.SetWindowTitle( "Select First Background Reference Image" ); if ( d.Execute() == StdDialogCode::Ok ) { instance.p_inputView[0].backgroundReferenceViewId = d.Id(); GUI->BackgroundReferenceView1_Edit.SetText( BACKGROUND_REFERENCE_ID1 ); } } else if ( sender == GUI->OutputBackgroundReferenceMask1_CheckBox ) instance.p_inputView[0].outputBackgroundReferenceMask = checked; else if ( sender == GUI->BackgroundROISelectPreview1_Button ) { PreviewSelectionDialog d; d.SetWindowTitle( "Select First Background ROI" ); if ( d.Execute() ) if ( !d.Id().IsEmpty() ) { View view = View::ViewById( d.Id() ); if ( !view.IsNull() ) instance.p_inputView[0].backgroundROI = view.Window().PreviewRect( view.Id() ); } } else if ( sender == GUI->BackgroundReferenceView2_ToolButton ) { ViewSelectionDialog d( instance.p_inputView[1].backgroundReferenceViewId ); d.SetWindowTitle( "Select Second Background Reference Image" ); if ( d.Execute() == StdDialogCode::Ok ) { instance.p_inputView[1].backgroundReferenceViewId = d.Id(); GUI->BackgroundReferenceView2_Edit.SetText( BACKGROUND_REFERENCE_ID2 ); } } else if ( sender == GUI->OutputBackgroundReferenceMask2_CheckBox ) instance.p_inputView[1].outputBackgroundReferenceMask = checked; else if ( sender == GUI->BackgroundROISelectPreview2_Button ) { PreviewSelectionDialog d; d.SetWindowTitle( "Select Second Background ROI" ); if ( d.Execute() ) if ( !d.Id().IsEmpty() ) { View view = View::ViewById( d.Id() ); if ( !view.IsNull() ) instance.p_inputView[1].backgroundROI = view.Window().PreviewRect( view.Id() ); } } UpdateControls(); }
bool ChannelCombinationInstance::ExecuteOn( View& view ) { ImageWindow sourceWindow[ 3 ]; ImageVariant sourceImage[ 3 ]; AutoViewLock lock( view ); ImageVariant image = view.Image(); if ( image.IsComplexSample() ) throw Error( "ChannelCombination cannot be executed on complex images." ); if ( image->ColorSpace() != ColorSpace::RGB ) throw Error( "ChannelCombination requires a RGB color image." ); Console().EnableAbort(); StandardStatus status; image->SetStatusCallback( &status ); String baseId; Rect r; int w0, h0; if ( view.IsPreview() ) { ImageWindow w = view.Window(); View mainView = w.MainView(); baseId = mainView.Id(); r = w.PreviewRect( view.Id() ); mainView.GetSize( w0, h0 ); } else { baseId = view.Id(); r = image->Bounds(); w0 = r.Width(); h0 = r.Height(); } int numberOfSources = 0; for ( int i = 0; i < 3; ++i ) if ( channelEnabled[i] ) { String id = channelId[i]; if ( id.IsEmpty() ) id = baseId + '_' + ColorSpaceId::ChannelId( colorSpace, i ); sourceWindow[i] = ImageWindow::WindowById( id ); if ( sourceWindow[i].IsNull() ) throw Error( "ChannelCombination: Source image not found: " + id ); sourceImage[i] = sourceWindow[i].MainView().Image(); if ( !sourceImage[i] ) throw Error( "ChannelCombination: Invalid source image: " + id ); if ( sourceImage[i]->IsColor() ) throw Error( "ChannelCombination: Invalid source color space: " + id ); if ( sourceImage[i]->Width() != w0 || sourceImage[i]->Height() != h0 ) throw Error( "ChannelCombination: Incompatible source image dimensions: " + id ); ++numberOfSources; } if ( numberOfSources == 0 ) return false; const char* what = ""; switch ( colorSpace ) { case ColorSpaceId::RGB: what = "RGB channels"; break; case ColorSpaceId::CIEXYZ: what = "normalized CIE XYZ components"; break; case ColorSpaceId::CIELab: what = "normalized CIE L*a*b* components"; break; case ColorSpaceId::CIELch: what = "normalized CIE L*c*h* components"; break; case ColorSpaceId::HSV: what = "normalized HSV components"; break; case ColorSpaceId::HSI: what = "normalized HSI components"; break; } image->Status().Initialize( String( "Combining " ) + what, image->NumberOfPixels() ); if ( image.IsFloatSample() ) switch ( image.BitsPerSample() ) { case 32: CombineChannels( static_cast<Image&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; case 64: CombineChannels( static_cast<DImage&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; } else switch ( image.BitsPerSample() ) { case 8: CombineChannels( static_cast<UInt8Image&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; case 16: CombineChannels( static_cast<UInt16Image&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; case 32: CombineChannels( static_cast<UInt32Image&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; } return true; }
void DrizzleIntegrationInterface::__Click( Button& sender, bool checked ) { if ( sender == GUI->AddFiles_PushButton ) { FileFilter drzFiles; drzFiles.SetDescription( "Drizzle Data Files" ); drzFiles.AddExtension( ".drz" ); OpenFileDialog d; d.EnableMultipleSelections(); d.Filters().Clear(); d.Filters().Add( drzFiles ); d.SetCaption( "DrizzleIntegration: Select Drizzle Data Files" ); if ( d.Execute() ) { size_type i0 = TreeInsertionIndex( GUI->InputData_TreeBox ); for ( StringList::const_iterator i = d.FileNames().Begin(); i != d.FileNames().End(); ++i ) m_instance.p_inputData.Insert( m_instance.p_inputData.At( i0++ ), DrizzleIntegrationInstance::DataItem( *i ) ); UpdateInputDataList(); UpdateDataSelectionButtons(); } } else if ( sender == GUI->SelectAll_PushButton ) { GUI->InputData_TreeBox.SelectAllNodes(); UpdateDataSelectionButtons(); } else if ( sender == GUI->InvertSelection_PushButton ) { for ( int i = 0, n = GUI->InputData_TreeBox.NumberOfChildren(); i < n; ++i ) GUI->InputData_TreeBox[i]->Select( !GUI->InputData_TreeBox[i]->IsSelected() ); UpdateDataSelectionButtons(); } else if ( sender == GUI->ToggleSelected_PushButton ) { for ( int i = 0, n = GUI->InputData_TreeBox.NumberOfChildren(); i < n; ++i ) if ( GUI->InputData_TreeBox[i]->IsSelected() ) m_instance.p_inputData[i].enabled = !m_instance.p_inputData[i].enabled; UpdateInputDataList(); UpdateDataSelectionButtons(); } else if ( sender == GUI->RemoveSelected_PushButton ) { DrizzleIntegrationInstance::input_data_list newImages; for ( int i = 0, n = GUI->InputData_TreeBox.NumberOfChildren(); i < n; ++i ) if ( !GUI->InputData_TreeBox[i]->IsSelected() ) newImages.Add( m_instance.p_inputData[i] ); m_instance.p_inputData = newImages; UpdateInputDataList(); UpdateDataSelectionButtons(); } else if ( sender == GUI->Clear_PushButton ) { m_instance.p_inputData.Clear(); UpdateInputDataList(); UpdateDataSelectionButtons(); } else if ( sender == GUI->FullPaths_CheckBox ) { UpdateInputDataList(); UpdateDataSelectionButtons(); } else if ( sender == GUI->InputDirectory_ToolButton ) { GetDirectoryDialog d; d.SetCaption( "DrizzleIntegration: Select Input Directory" ); if ( d.Execute() ) GUI->InputDirectory_Edit.SetText( m_instance.p_inputDirectory = d.Directory() ); } else if ( sender == GUI->EnableRejection_CheckBox ) { m_instance.p_enableRejection = checked; } else if ( sender == GUI->EnableImageWeighting_CheckBox ) { m_instance.p_enableImageWeighting = checked; } else if ( sender == GUI->EnableSurfaceSplines_CheckBox ) { m_instance.p_enableSurfaceSplines = checked; } else if ( sender == GUI->ClosePreviousImages_CheckBox ) { m_instance.p_closePreviousImages = checked; } else if ( sender == GUI->SelectPreview_Button ) { PreviewSelectionDialog d; if ( d.Execute() ) if ( !d.Id().IsEmpty() ) { View view = View::ViewById( d.Id() ); if ( !view.IsNull() ) { m_instance.p_roi = view.Window().PreviewRect( view.Id() ); UpdateROIControls(); } } } }