Skip to content

Commit

Permalink
Working on a generic composite area.
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalhorton committed Mar 21, 2018
1 parent 8899b81 commit 697f25c
Show file tree
Hide file tree
Showing 5 changed files with 359 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/shared_base/core/asArea.h
Expand Up @@ -37,7 +37,7 @@ class asArea
public:
enum GridType
{
Regular, GaussianT62, GaussianT382, Undefined
Regular, GaussianT62, GaussianT382, Generic, Undefined
};

asArea(const Coo &cornerUL, const Coo &cornerUR, const Coo &cornerLL, const Coo &cornerLR, float level = asNONE,
Expand Down
251 changes: 251 additions & 0 deletions src/shared_base/core/asAreaCompGenGrid.cpp
@@ -0,0 +1,251 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can read the License at http://opensource.org/licenses/CDDL-1.0
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL Header Notice in
* each file and include the License file (licence.txt). If applicable,
* add the following below this CDDL Header, with the fields enclosed
* by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* The Original Software is AtmoSwing.
* The Original Software was developed at the University of Lausanne.
* All Rights Reserved.
*
*/

/*
* Portions Copyright 2018 Pascal Horton, University of Bern.
*/

#include "asAreaCompGenGrid.h"

asAreaCompGenGrid::asAreaCompGenGrid(const Coo &cornerUL, const Coo &cornerUR, const Coo &cornerLL, const Coo &cornerLR,
float level, float height, int flatAllowed)
: asAreaCompGrid(cornerUL, cornerUR, cornerLL, cornerLR, level, height, flatAllowed),
m_xPtsNb(0),
m_yPtsNb(0)
{
m_gridType = Generic;
m_axesInitialized = false;
}

asAreaCompGenGrid::asAreaCompGenGrid(double xMin, double xWidth, double yMin, double yWidth, float level, float height,
int flatAllowed)
: asAreaCompGrid(xMin, xWidth, yMin, yWidth, level, height, flatAllowed),
m_xPtsNb(0),
m_yPtsNb(0)
{
m_gridType = Generic;
m_axesInitialized = false;
}

asAreaCompGenGrid::asAreaCompGenGrid(double xMin, int xPtsNb, double yMin, int yPtsNb, float level, float height,
int flatAllowed)
: asAreaCompGrid(xMin, 0, yMin, 0, level, height, flatAllowed),
m_xPtsNb(xPtsNb),
m_yPtsNb(yPtsNb)
{
m_gridType = Generic;
m_axesInitialized = false;
}

bool asAreaCompGenGrid::GridsOverlay(asAreaCompGrid *otherarea) const
{
return false;
}

a1d asAreaCompGenGrid::GetXaxisComposite(int compositeNb)
{
double xMin = GetComposite(compositeNb).GetXmin();
double xMax = GetComposite(compositeNb).GetXmax();

int xMinIndex = asFind(&m_fullAxisX[0], &m_fullAxisX[m_fullAxisX.size() - 1], xMin, 0.01);
int xMaxIndex = asFind(&m_fullAxisX[0], &m_fullAxisX[m_fullAxisX.size() - 1], xMax, 0.01);

wxASSERT(xMinIndex >= 0);
wxASSERT(xMaxIndex >= 0);
wxASSERT(xMaxIndex >= xMinIndex);

return m_fullAxisX.segment(xMinIndex, xMaxIndex - xMinIndex + 1);
}

a1d asAreaCompGenGrid::GetYaxisComposite(int compositeNb)
{
double yMin = GetComposite(compositeNb).GetYmin();
double yMax = GetComposite(compositeNb).GetYmax();

int yMinIndex = asFind(&m_fullAxisY[0], &m_fullAxisY[m_fullAxisY.size() - 1], yMin, 0.01);
int yMaxIndex = asFind(&m_fullAxisY[0], &m_fullAxisY[m_fullAxisY.size() - 1], yMax, 0.01);

wxASSERT(yMinIndex >= 0);
wxASSERT(yMaxIndex >= 0);
wxASSERT(yMaxIndex >= yMinIndex);

return m_fullAxisY.segment(yMinIndex, yMaxIndex - yMinIndex + 1);
}

int asAreaCompGenGrid::GetXaxisCompositePtsnb(int compositeNb)
{
double xMin = GetComposite(compositeNb).GetXmin();
double xMax = GetComposite(compositeNb).GetXmax();

int xMinIndex = asFind(&m_fullAxisX[0], &m_fullAxisX[m_fullAxisX.size() - 1], xMin, 0.01);
int xMaxIndex = asFind(&m_fullAxisX[0], &m_fullAxisX[m_fullAxisX.size() - 1], xMax, 0.01);

wxASSERT(xMinIndex >= 0);
wxASSERT(xMaxIndex >= 0);

int ptsnb = xMaxIndex - xMinIndex;

if (compositeNb == 0) // from 0
{
ptsnb += 1;
} else if (compositeNb == 1) // to 360
{
ptsnb += 1;
} else {
asThrowException(_("The latitude split is not implemented yet."));
}

return ptsnb;
}

int asAreaCompGenGrid::GetYaxisCompositePtsnb(int compositeNb)
{
double yMin = GetComposite(compositeNb).GetYmin();
double yMax = GetComposite(compositeNb).GetYmax();

int yMinIndex = asFind(&m_fullAxisY[0], &m_fullAxisY[m_fullAxisY.size() - 1], yMin, 0.01);
int yMaxIndex = asFind(&m_fullAxisY[0], &m_fullAxisY[m_fullAxisY.size() - 1], yMax, 0.01);

wxASSERT(yMinIndex >= 0);
wxASSERT(yMaxIndex >= 0);

int ptsnb = yMaxIndex - yMinIndex;
ptsnb += 1;

return ptsnb;
}

double asAreaCompGenGrid::GetXaxisCompositeWidth(int compositeNb) const
{
return std::abs(GetComposite(compositeNb).GetXmax() - GetComposite(compositeNb).GetXmin());
}

double asAreaCompGenGrid::GetYaxisCompositeWidth(int compositeNb) const
{
return std::abs(GetComposite(compositeNb).GetYmax() - GetComposite(compositeNb).GetYmin());
}

double asAreaCompGenGrid::GetXaxisCompositeStart(int compositeNb) const
{
// If only one composite
if (GetNbComposites() == 1) {
return GetComposite(compositeNb).GetXmin();
}

// If multiple composites
if (compositeNb == 0) // from 0
{
return GetComposite(compositeNb).GetXmin();
} else if (compositeNb == 1) // to 360
{
return GetComposite(compositeNb).GetXmin();
} else {
asThrowException(_("The latitude split is not implemented yet."));
}
}

double asAreaCompGenGrid::GetYaxisCompositeStart(int compositeNb) const
{
// If only one composite
if (GetNbComposites() == 1) {
return GetComposite(compositeNb).GetYmin();
}

// If multiple composites
if (compositeNb == 0) // from 0
{
return GetComposite(compositeNb).GetYmin();
} else if (compositeNb == 1) // to 360
{
return GetComposite(compositeNb).GetYmin();
} else {
asThrowException(_("The latitude split is not implemented yet."));
}
}

double asAreaCompGenGrid::GetXaxisCompositeEnd(int compositeNb) const
{
// If only one composite
if (GetNbComposites() == 1) {
return GetComposite(compositeNb).GetXmax();
}

// If multiple composites
if (compositeNb == 1) // to 360
{
return GetComposite(compositeNb).GetXmax();
} else if (compositeNb == 0) // from 0
{
return GetComposite(compositeNb).GetXmax();
} else {
asThrowException(_("The latitude split is not implemented yet."));
}
}

double asAreaCompGenGrid::GetYaxisCompositeEnd(int compositeNb) const
{
// If only one composite
if (GetNbComposites() == 1) {
return GetComposite(compositeNb).GetYmax();
}

// If multiple composites
if (compositeNb == 1) // to 360
{
return GetComposite(compositeNb).GetYmax();
} else if (compositeNb == 0) // from 0
{
return GetComposite(compositeNb).GetYmax();
} else {
asThrowException(_("The latitude split is not implemented yet."));
}
}

bool asAreaCompGenGrid::IsOnGrid(const Coo &point) const
{
if (!IsRectangle())
return false;

int foundX = asFind(&m_fullAxisX[0], &m_fullAxisX[m_fullAxisX.size() - 1], point.x, 0.01);
if ((foundX == asNOT_FOUND) || (foundX == asOUT_OF_RANGE))
return false;

int foundY = asFind(&m_fullAxisY[0], &m_fullAxisY[m_fullAxisY.size() - 1], point.y, 0.01);
if ((foundY == asNOT_FOUND) || (foundY == asOUT_OF_RANGE))
return false;

return true;
}

bool asAreaCompGenGrid::IsOnGrid(double xCoord, double yCoord) const
{
int foundX = asFind(&m_fullAxisX[0], &m_fullAxisX[m_fullAxisX.size() - 1], xCoord, 0.01);
if ((foundX == asNOT_FOUND) || (foundX == asOUT_OF_RANGE))
return false;

int foundY = asFind(&m_fullAxisY[0], &m_fullAxisY[m_fullAxisY.size() - 1], yCoord, 0.01);
if ((foundY == asNOT_FOUND) || (foundY == asOUT_OF_RANGE))
return false;

return true;
}
94 changes: 94 additions & 0 deletions src/shared_base/core/asAreaCompGenGrid.h
@@ -0,0 +1,94 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can read the License at http://opensource.org/licenses/CDDL-1.0
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL Header Notice in
* each file and include the License file (licence.txt). If applicable,
* add the following below this CDDL Header, with the fields enclosed
* by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* The Original Software is AtmoSwing.
* The Original Software was developed at the University of Lausanne.
* All Rights Reserved.
*
*/

/*
* Portions Copyright 2018 Pascal Horton, University of Bern.
*/

#ifndef asAreaCompositeGenGrid_H
#define asAreaCompositeGenGrid_H

#include <asIncludes.h>
#include <asAreaCompGrid.h>

class asAreaCompGenGrid
: public asAreaCompGrid
{
public:
asAreaCompGenGrid(const Coo &cornerUL, const Coo &cornerUR, const Coo &cornerLL, const Coo &cornerLR,
float level = asNONE, float height = asNONE, int flatAllowed = asFLAT_FORBIDDEN);

asAreaCompGenGrid(double xMin, double xWidth, double yMin, double yWidth, float level = asNONE,
float height = asNONE, int flatAllowed = asFLAT_FORBIDDEN);

asAreaCompGenGrid(double xMin, int xPtsNb, double yMin, int yPtsNb, float level = asNONE, float height = asNONE,
int flatAllowed = asFLAT_FORBIDDEN);

~asAreaCompGenGrid() override = default;

bool GridsOverlay(asAreaCompGrid *otherarea) const;

double GetXstep() const override
{
return 0.0;
}

double GetYstep() const override
{
return 0.0;
}

a1d GetXaxisComposite(int compositeNb) override;

a1d GetYaxisComposite(int compositeNb) override;

int GetXaxisCompositePtsnb(int compositeNb) override;

int GetYaxisCompositePtsnb(int compositeNb) override;

double GetXaxisCompositeWidth(int compositeNb) const override;

double GetYaxisCompositeWidth(int compositeNb) const override;

double GetXaxisCompositeStart(int compositeNb) const override;

double GetYaxisCompositeStart(int compositeNb) const override;

double GetXaxisCompositeEnd(int compositeNb) const override;

double GetYaxisCompositeEnd(int compositeNb) const override;

protected:

private:
a1d m_fullAxisX;
a1d m_fullAxisY;
int m_xPtsNb;
int m_yPtsNb;

bool IsOnGrid(const Coo &point) const;

bool IsOnGrid(double xCoord, double yCoord) const;
};

#endif // asAreaCompositeGenGrid_H
12 changes: 8 additions & 4 deletions src/shared_base/core/asAreaCompGrid.cpp
Expand Up @@ -30,6 +30,7 @@
#include "asAreaCompRegGrid.h"
#include "asAreaGaussGrid.h"
#include "asAreaCompGaussGrid.h"
#include "asAreaCompGenGrid.h"

asAreaCompGrid * asAreaCompGrid::GetInstance(const wxString &type, double xMin, int xPtsNb, double xStep, double yMin,
int yPtsNb, double yStep, float level, float height, int flatAllowed)
Expand All @@ -56,6 +57,9 @@ asAreaCompGrid * asAreaCompGrid::GetInstance(const wxString &type, double xMin,
asAreaCompGrid *area = new asAreaCompGaussGrid(xMin, xPtsNb, yMin, yPtsNb, GaussianT382, level, height,
flatAllowed);
return area;
} else if (type.IsSameAs("Generic", false)) {
asAreaCompGrid *area = new asAreaCompGenGrid(xMin, xPtsNb, yMin, yPtsNb, level, height, flatAllowed);
return area;
} else {
wxLogError(_("Given grid type: %s"), type);
asThrowException("The given grid type doesn't correspond to any existing option.");
Expand Down Expand Up @@ -122,15 +126,15 @@ a1d asAreaCompGrid::GetYaxis(const wxString &type, double yMin, double yMax, dou
return axis.segment(start, end - start + 1);
}

asAreaCompGrid::asAreaCompGrid(const Coo &cornerUL, const Coo &cornerUR, const Coo &cornerLL,
const Coo &cornerLR, float level, float height, int flatAllowed)
asAreaCompGrid::asAreaCompGrid(const Coo &cornerUL, const Coo &cornerUR, const Coo &cornerLL, const Coo &cornerLR,
float level, float height, int flatAllowed)
: asAreaComp(cornerUL, cornerUR, cornerLL, cornerLR, level, height, flatAllowed),
m_axesInitialized(false)
{
}

asAreaCompGrid::asAreaCompGrid(double xMin, double xWidth, double yMin, double yWidth, float level,
float height, int flatAllowed)
asAreaCompGrid::asAreaCompGrid(double xMin, double xWidth, double yMin, double yWidth, float level, float height,
int flatAllowed)
: asAreaComp(xMin, xWidth, yMin, yWidth, level, height, flatAllowed),
m_axesInitialized(false)
{
Expand Down

0 comments on commit 697f25c

Please sign in to comment.