Skip to content

Commit

Permalink
Merge pull request #167 from Astroua/develop
Browse files Browse the repository at this point in the history
New 0.6.2 release
  • Loading branch information
alexstrilets committed Jun 7, 2016
2 parents 65fd57e + 702c788 commit 7009a6a
Show file tree
Hide file tree
Showing 160 changed files with 8,948 additions and 1,661 deletions.
2 changes: 2 additions & 0 deletions carta/cpp/CartaLib/CartaLib.pro
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SOURCES += \
Hooks/ImageStatisticsHook.cpp \
Hooks/LoadRegion.cpp \
Hooks/Plot2DResult.cpp \
Hooks/ProfileResult.cpp \
IImage.cpp \
PixelType.cpp \
Slice.cpp \
Expand Down Expand Up @@ -60,6 +61,7 @@ HEADERS += \
Hooks/ImageStatisticsHook.h \
Hooks/LoadRegion.h \
Hooks/Plot2DResult.h \
Hooks/ProfileResult.h \
IPlugin.h \
IImage.h \
PixelType.h \
Expand Down
10 changes: 7 additions & 3 deletions carta/cpp/CartaLib/Hooks/ProfileHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
**/

#pragma once

#include "ProfileResult.h"
#include "CartaLib/CartaLib.h"
#include "CartaLib/IPlugin.h"
#include "CartaLib/RegionInfo.h"
#include "CartaLib/ProfileInfo.h"
#include "CartaLib/Hooks/ProfileResult.h"

namespace Carta
{
Expand All @@ -19,13 +20,16 @@ class ImageInterface;
}
namespace Hooks
{



class ProfileHook : public BaseHook
{
CARTA_HOOK_BOILER1( ProfileHook );

public:
//The intensity counts
typedef std::vector<double> ResultType;
//The results from generating a profile.
typedef Carta::Lib::Hooks::ProfileResult ResultType;

/**
* @brief Params
Expand Down
83 changes: 83 additions & 0 deletions carta/cpp/CartaLib/Hooks/ProfileResult.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <CartaLib/Hooks/ProfileResult.h>
#include <QDebug>

namespace Carta {
namespace Lib {
namespace Hooks {

ProfileResult::ProfileResult( double restFrequency, const QString& restUnits,
const std::vector< std::pair<double,double> > data){
m_data = data;
m_restUnits = restUnits;
m_restFrequency = restFrequency;
}

std::vector< std::pair<double,double> > ProfileResult::getData() const {
return m_data;
}

QString ProfileResult::getError() const {
return m_errorMessage;
}

QString ProfileResult::getRestUnits() const {
return m_restUnits;
}

double ProfileResult::getRestFrequency() const {
return m_restFrequency;
}


void ProfileResult::setData( const std::vector< std::pair<double,double> >& data ){
m_data = data;
}

void ProfileResult::setRestFrequency( double restFreq ){
m_restFrequency = restFreq;
}

void ProfileResult::setRestUnits( const QString& restUnits ){
m_restUnits = restUnits;
}

void ProfileResult::setError( const QString& errorMsg ){
m_errorMessage = errorMsg;
}

QDataStream &operator<<(QDataStream& out, const ProfileResult& result ){
out << result.getRestUnits()<< result.getRestFrequency();
std::vector<std::pair<double,double>> data = result.getData();
int dataCount = data.size();
out << dataCount;
for ( int i = 0; i < dataCount; i++ ){
out << data[i].first << data[i].second;
}
return out;
}


QDataStream &operator>>(QDataStream& in, ProfileResult& result ){
QString name;
QString unitsX;
QString unitsY;

double restFrequency;
QString restUnits;
int dataCount;
in >> restUnits >> restFrequency;
in >> dataCount;
std::vector<std::pair<double,double> > data( dataCount );
for ( int i = 0; i < dataCount; i++ ){
double firstEle;
double secondEle;
in >> firstEle >> secondEle;
data[i] = std::pair<double,double>( firstEle, secondEle );
}
result = ProfileResult( restFrequency, restUnits, data );
return in;
}

}
}
}
85 changes: 85 additions & 0 deletions carta/cpp/CartaLib/Hooks/ProfileResult.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Stores profile data and associated information needed to display a profile and
* information about the profile.
*/
#pragma once
#include <QString>
#include <vector>
#include "CartaLib/ProfileInfo.h"

namespace Carta{
namespace Lib{

namespace Hooks {

class ProfileResult {


public:
ProfileResult( double imageRest = 0, const QString& restUnits = "",
const std::vector< std::pair<double, double> > data = std::vector< std::pair<double,double> >());

/**
* Return (x,y) data pairs that comprise a profile.
* @return - (x,y) data pairs that comprise a profile curve.
*/
std::vector< std::pair<double,double> > getData() const;

/**
* Return information about any errors that prevented the computation of a profile.
* @return - an error message or an empty string if no errors were encountered.
*/
QString getError() const;

/**
* Returns the image rest frequency units.
* @return - the image rest frequency units.
*/
QString getRestUnits() const;

/**
* Returns the image rest frequency.
* @return - the image rest frequency.
*/
double getRestFrequency() const;

/**
* Store the (x,y) data pairs that comprise a profile.
* @param data - the (x,y) data pairs that make up a profile.
*/
void setData( const std::vector< std::pair<double,double> >& data );

/**
* Set an error message if there was a problem computing the profile.
* @param errorMessage - a description of the problem.
*/
void setError( const QString& errorMsg );

/**
* Store the image rest frequency.
* @param restFreq - the image rest frequency.
*/
void setRestFrequency( double restFreq );

/**
* Store the image rest units.
* @param restUnits - the image rest units.
*/
void setRestUnits( const QString& restUnits );

virtual ~ProfileResult(){}

private:
std::vector< std::pair<double,double> > m_data;
double m_restFrequency;
QString m_restUnits;
QString m_errorMessage;
};

//Serialization so that the profile result can be generated in a separate process.
QDataStream &operator<<(QDataStream& out, const Carta::Lib::Hooks::ProfileResult& result );
QDataStream &operator>>(QDataStream& in, Carta::Lib::Hooks::ProfileResult& result );

}
}
}
54 changes: 51 additions & 3 deletions carta/cpp/CartaLib/ProfileInfo.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#include "ProfileInfo.h"
#include <cmath>

namespace Carta {
namespace Lib {

ProfileInfo::ProfileInfo(){
m_aggregateType = AggregateType::MEAN;
m_spectralType = "default";
m_restFrequency = 0;
m_restUnit = "GHz";
m_restUnit = "";
m_spectralUnit = "pixel";
}

ProfileInfo::AggregateType ProfileInfo::getAggregateType() const {
Expand All @@ -20,10 +24,54 @@ QString ProfileInfo::getRestUnit() const {
return m_restUnit;
}

QString ProfileInfo::getSpectralType() const {
return m_spectralType;
}

QString ProfileInfo::getSpectralUnit() const {
return m_spectralUnit;
}

bool ProfileInfo::operator==( const ProfileInfo& rhs ) {
bool equalProfiles = false;
if ( m_aggregateType == rhs.m_aggregateType ){
if ( m_restUnit == rhs.m_restUnit ){
if ( m_spectralType == rhs.m_spectralType ){
if ( m_spectralUnit == rhs.m_spectralUnit ){
const double ERROR_MARGIN = 0.000001;
if ( fabs( m_restFrequency - rhs.m_restFrequency ) < ERROR_MARGIN ){
equalProfiles = true;
}
}
}
}
}
return equalProfiles;
}

bool ProfileInfo::operator!=( const ProfileInfo& rhs ) {
return !( *this== rhs );
}

ProfileInfo & ProfileInfo::setAggregateType( const ProfileInfo::AggregateType & knownType ){
void ProfileInfo::setAggregateType( const ProfileInfo::AggregateType & knownType ){
m_aggregateType = knownType;
return * this;
}

void ProfileInfo::setRestFrequency( double freq ) {
m_restFrequency = freq;
}


void ProfileInfo::setRestUnit( const QString& unit ){
m_restUnit = unit;
}

void ProfileInfo::setSpectralType( const QString& specType ){
m_spectralType = specType;
}

void ProfileInfo::setSpectralUnit( const QString& specUnit ){
m_spectralUnit = specUnit;
}

ProfileInfo::~ProfileInfo(){
Expand Down
69 changes: 63 additions & 6 deletions carta/cpp/CartaLib/ProfileInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class ProfileInfo
{
public:
/// Methods of summarizing profiles
enum class AggregateType
{
enum class AggregateType {
MEAN,
MEDIAN,
RMS,
Expand All @@ -35,8 +34,8 @@ class ProfileInfo
AggregateType getAggregateType() const;

/**
* Return the rest frequency used in generating the profile.
* @return - the rest frequency used in generating the profile.
* Return the rest frequency in the image.
* @return - the rest frequency in the image.
*/
double getRestFrequency() const;

Expand All @@ -46,18 +45,76 @@ class ProfileInfo
*/
QString getRestUnit() const;

/**
* Return a string indicating the profile spectral type
* (for example, 'radio velocity' or 'optical velocity').
* @return - a string representing the general category
* of spectral units.
*/
QString getSpectralType() const;

/**
* Return the actual spectral unit such as 'MHz' or 'mm'.
* @return - the spectral unit.
*/
QString getSpectralUnit() const;

/**
* Equality operator.
* @param rhs - the other ProfileInfo to compare to.
* @return true if the other ProfileInfo matches this one; false otherwise.
*/
bool operator==( const ProfileInfo& rhs );

/**
* Inequality operator.
* @param rhs - the other ProfileInfo to compare to.
* @return true if the other ProfileInfo does not match this one; false otherwise.
*/
bool operator!=( const ProfileInfo& rhs );

/**
* Set the method used for aggregating data.
* @param aggType - the method used for aggregating data.
*/
ProfileInfo & setAggregateType( const AggregateType & aggType );
void setAggregateType( const AggregateType & aggType );

/**
* Set the rest frequency.
* @param freq - the rest frequency used in the profile
* calculation.
*/
void setRestFrequency( double freq );

/**
* Set a string indicating the general category of spectral
* units.
* @param specType - a string indicating the general category
* of spectral units.
*/
void setSpectralType( const QString& specType );

/**
* Set the rest frequency units.
* @param unit - the rest frequency units.
*/
void setRestUnit( const QString& unit );

/**
* Set the spectral units such as "mm" or "GHz".
* @param unit - the actual units to use in calculating the
* profile.
*/
void setSpectralUnit( const QString& unit );

virtual ~ProfileInfo();

protected:
AggregateType m_aggregateType = AggregateType::OTHER;
AggregateType m_aggregateType;
double m_restFrequency;
QString m_restUnit;
QString m_spectralUnit;
QString m_spectralType;
};

} // namespace Lib
Expand Down
Loading

0 comments on commit 7009a6a

Please sign in to comment.