Example #1
0
   static void EvaluateNoise( FVector& noiseEstimates,
                              FVector& noiseFractions,
                              StringList& noiseAlgorithms,
                              const Image& image, int algorithm )
   {
      SpinStatus spin;
      image.SetStatusCallback( &spin );
      image.Status().Initialize( "Noise evaluation" );
      image.Status().DisableInitialization();

      Console console;

      int numberOfThreads = Thread::NumberOfThreads( image.NumberOfPixels(), 1 );
      if ( numberOfThreads >= 3 )
      {
         int numberOfSubthreads = RoundI( numberOfThreads/3.0 );
         ReferenceArray<NoiseEvaluationThread> threads;
         threads.Add( new NoiseEvaluationThread( image, 0, algorithm, numberOfSubthreads ) );
         threads.Add( new NoiseEvaluationThread( image, 1, algorithm, numberOfSubthreads ) );
         threads.Add( new NoiseEvaluationThread( image, 2, algorithm, numberOfThreads - 2*numberOfSubthreads ) );

         AbstractImage::ThreadData data( image, 0 ); // unbounded
         AbstractImage::RunThreads( threads, data );

         for ( int i = 0; i < 3; ++i )
         {
            noiseEstimates[i]  = threads[i].noiseEstimate;
            noiseFractions[i]  = threads[i].noiseFraction;
            noiseAlgorithms[i] = String( threads[i].noiseAlgorithm );
         }

         threads.Destroy();
      }
      else
      {
         for ( int i = 0; i < 3; ++i )
         {
            NoiseEvaluationThread thread( image, i, algorithm, 1 );
            thread.Run();
            noiseEstimates[i]  = thread.noiseEstimate;
            noiseFractions[i]  = thread.noiseFraction;
            noiseAlgorithms[i] = String( thread.noiseAlgorithm );
         }
      }

      image.ResetSelections();
      image.Status().Complete();

      console.WriteLn( "<end><cbr>Gaussian noise estimates:" );
      for ( int i = 0; i < 3; ++i )
         console.WriteLn( String().Format( "s%d = %.3e, n%d = %.4f ",
                              i, noiseEstimates[i], i, noiseFractions[i] ) + '(' + noiseAlgorithms[i] + ')' );
   }
Example #2
0
GradientsBase::TimeMessage::TimeMessage(String const &rsTitle_p)
  :m_sMessage(rsTitle_p)
  //,m_startTime(boost::posix_time::microsec_clock::universal_time())
  ,m_bStopped(false)
{
  gettimeofday( &m_startTv, 0 );
  Console console;
  console.WriteLn(String("Start: ")+m_sMessage);
  ProcessInterface::ProcessEvents ();
}
bool INDIDeviceControllerInstance::ExecuteGlobal()
{
   Console console;

   Exception::DisableGUIOutput();

   INDIClient* indi = INDIClient::TheClient();

   try
   {
      if ( p_serverConnect )
      {
         if ( indi == nullptr )
         {
            indi = INDIClient::NewClient( p_serverHostName.ToUTF8(), p_serverPort );
            if ( p_verbosity > 0 )
            {
               console.NoteLn( "<end><cbr>INDI Control Client --- (C) Klaus Kretzschmar, 2014-2016" );
               console.Flush();
            }
         }

         indi->SetVerbosity( p_verbosity );

         if ( !indi->IsServerConnected() )
         {
            indi->connectServer();
            if ( !indi->IsServerConnected() )
               throw Error( "INDIDeviceControllerInstance: Failure to connect to INDI server " + p_serverHostName + ", port=" + String( p_serverPort ) );

            if ( p_verbosity > 0 )
            {
               console.NoteLn( "* Successfully connected to INDI server " + p_serverHostName + ", port=" + String( p_serverPort ) );
               console.Flush();
            }
         }

         if ( !p_serverCommand.IsEmpty() )
         {
            console.EnableAbort();

            if ( p_serverCommand == "GET" )
            {
               o_getCommandResult.Clear();
               String device( PropertyUtils::Device( p_getCommandParameters ) );
               String property( PropertyUtils::Property( p_getCommandParameters ) );
               String element( PropertyUtils::Element( p_getCommandParameters ) );
               INDIPropertyListItem item;
               if ( !indi->GetPropertyItem( device, property, element, item ) )
                  throw Error( "INDIDeviceControllerInstance: Could not get value of property '" + String( p_getCommandParameters ) + "'" );
               o_getCommandResult = item.PropertyValue;
               if ( p_verbosity > 1 )
                  console.WriteLn( "<end><cbr>Device=" + device +
                                   ", Property=" + property +
                                   ", Element=" + element +
                                   ", Value=" + o_getCommandResult );
            }
            else if ( p_serverCommand == "SET" )
            {
               for ( auto newProperty : p_newProperties )
               {
                  GetNewPropertyListItemParametersFromKey( newProperty );
                  if ( !indi->SendNewPropertyItem( newProperty, false/*async*/ ) )
                     throw Error( "INDIDeviceControllerInstance: Failure to send new property values." );
               }
               p_newProperties.Clear();
            }
            else if ( p_serverCommand == "SET_ASYNC" )
            {
               for ( auto newProperty : p_newProperties )
               {
                  GetNewPropertyListItemParametersFromKey( newProperty );
                  if ( !indi->SendNewPropertyItem( newProperty, true/*async*/ ) )
                     throw Error( "INDIDeviceControllerInstance: Failure to send new property values (asynchronous)." );
               }
               p_newProperties.Clear();
            }
            else
               throw Error( "INDIDeviceControllerInstance: Unknown command '" + p_serverCommand + "'" );

            console.Flush();
         }

         AcquireINDIClientProperties();
      }
      else
      {
         if ( indi != nullptr )
         {
            if ( indi->IsServerConnected() )
            {
               AcquireINDIClientProperties();
               indi->SetVerbosity( p_verbosity );
               indi->disconnectServer();
               if ( p_verbosity > 0 )
                  console.NoteLn( "* Disconnected from INDI server " + p_serverHostName + ", port=" + String( p_serverPort ) );
            }

            INDIClient::DestroyClient();
         }
      }

      return true;
   }
   catch ( const Exception& x )
   {
      if ( p_verbosity > 0 )
         x.Show();
      return false;
   }
   catch ( ... )
   {
      throw;
   }
}