Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes #116

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e18c162
Applied clang format.
Mar 26, 2019
9a83599
Resolved merge conflict.
Jul 5, 2019
1656583
Fixed double clicking not detected correctly.
embeddedmz Aug 17, 2019
58f1e2c
Changed char* and strdup by std::string to fix a memory leak.
embeddedmz Aug 22, 2019
cd1b8ad
Fixed compiler warnings.
embeddedmz Aug 22, 2019
356eec0
Fixed old stations markers not cleared when new ones are requested.
embeddedmz Aug 22, 2019
cd81017
Unregister is overidden instead of Delete to allow VTK smart pointers…
embeddedmz Aug 22, 2019
f22620c
Fixed compiler warnings.
embeddedmz Aug 22, 2019
947b880
Added missing check on keys pointer that lead to a crash when using t…
embeddedmz Aug 22, 2019
e13ebc8
Removed an old instruction I forgot to remove in one of the previous …
embeddedmz Aug 22, 2019
0bf7e2b
Made several changes to avoid assigning existing nodes and markers ID…
embeddedmz Aug 22, 2019
8bdb38f
Fixed current clustering tree depth not used in RecomputeClusters() a…
Sep 25, 2019
9047609
Added the mention that the project is a C++/Qt slippy map.
Oct 7, 2019
2233986
Fixed DeleteAllMarkers not updating the modified state of the object.
Oct 7, 2019
c1a7956
Fixed OSM server sending invalid tiles due to a missing user agent.
Jan 6, 2020
ff5ffe2
Fixed libcurl dependency not visible in some applications that need t…
May 5, 2020
1679882
Fixed vtkMapMarkerSet's visibility not updating.
May 5, 2020
9f06d3e
Fixed incorrect rendering (missing tiles/blank regions) when when zoo…
May 10, 2020
235e487
Fixed discontinuities between tiles (altered tiles borders).
May 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
vtkMap is a project wich adds VTK support for Geovisualization in 2D and 3D.

It's a slippy map that can be used in C++/Qt programs.

Requirements
------------
* C++11
Expand Down
2 changes: 1 addition & 1 deletion applications/examples/example.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ int main(int argc, char* argv[])
}

vtkNew<vtkRenderWindow> wind;
wind->SetMultiSamples(0); // MSAA will create interpolated pixels
wind->AddRenderer(rend.GetPointer());
;
//wind->SetSize(1920, 1080);
wind->SetSize(800, 600);

Expand Down
2 changes: 1 addition & 1 deletion applications/examples/exampleLayers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ int main(int argc, char* argv[])
osmLayer->Delete();

vtkNew<vtkRenderWindow> wind;
wind->SetMultiSamples(0); // MSAA will create interpolated pixels
wind->AddRenderer(rend.GetPointer());
;
wind->SetSize(800, 600);

vtkNew<vtkRenderWindowInteractor> intr;
Expand Down
1 change: 1 addition & 0 deletions applications/examples/markerSize.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ int main(int argc, char* argv[])
osmLayer->Delete();

vtkNew<vtkRenderWindow> wind;
wind->SetMultiSamples(0); // MSAA will create interpolated pixels
wind->AddRenderer(rend.GetPointer());
wind->SetSize(800, 600);

Expand Down
8 changes: 7 additions & 1 deletion applications/weatherstations/qtMapCoordinatesWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@
// ------------------------------------------------------------
qtMapCoordinatesWidget::qtMapCoordinatesWidget(QWidget* parent)
: QWidget(parent)
, Map(0)
, Map(nullptr)
{
this->UI = new Ui_qtMapCoordinatesWidget;
this->UI->setupUi(this);
}

// ------------------------------------------------------------
qtMapCoordinatesWidget::~qtMapCoordinatesWidget()
{
delete this->UI;
}

// ------------------------------------------------------------
void qtMapCoordinatesWidget::setCoordinates(double center[2], int zoom)
{
Expand Down
1 change: 1 addition & 0 deletions applications/weatherstations/qtMapCoordinatesWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class qtMapCoordinatesWidget : public QWidget
Q_OBJECT
public:
qtMapCoordinatesWidget(QWidget* parent = 0);
~qtMapCoordinatesWidget() override;

void setCoordinates(double center[2], int zoom);
void getCoordinates(double center[2], int& zoom) const;
Expand Down
37 changes: 27 additions & 10 deletions applications/weatherstations/qtWeatherStations.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace
// Writes input buffer to stream (last argument)
size_t handle_curl_input(void* buffer, size_t size, size_t nmemb, void* stream)
{
(void) size;
//std::cout << "handle_input() nmemb: " << nmemb << std::endl
//std::cout << static_cast<char *>(buffer) << std::endl;
std::stringstream* ss = static_cast<std::stringstream*>(stream);
Expand All @@ -67,8 +68,9 @@ class MapCallback : public vtkCallbackCommand
{
}

virtual void Execute(vtkObject* caller, unsigned long eventId, void* data)
void Execute(vtkObject* caller, unsigned long eventId, void* data) override
{
(void) caller;
switch (eventId)
{
case vtkInteractorStyleGeoMap::SelectionCompleteEvent:
Expand Down Expand Up @@ -151,7 +153,7 @@ qtWeatherStations::qtWeatherStations(QWidget* parent)
//this->resetMapCoords();
//this->Map->SetCenter(32.2, -90.9); // approx ERDC coords
double centerLatLon[2] = { 42.849604, -73.758345 }; // KHQ coords
double zoom = 5;
int zoom = 5;
this->Map->SetCenter(centerLatLon);
this->Map->SetZoom(zoom);
this->UI->MapCoordinatesWidget->setCoordinates(centerLatLon, zoom);
Expand All @@ -166,6 +168,7 @@ qtWeatherStations::qtWeatherStations(QWidget* parent)
markerLayer->AddFeature(this->MapMarkers);

vtkNew<vtkRenderWindow> mapRenderWindow;
mapRenderWindow->SetMultiSamples(0);
mapRenderWindow->AddRenderer(this->Renderer);
this->MapWidget->SetRenderWindow(mapRenderWindow.GetPointer());

Expand Down Expand Up @@ -219,6 +222,8 @@ qtWeatherStations::~qtWeatherStations()
{
this->InteractorCallback->Delete();
}

delete this->UI;
}

// ------------------------------------------------------------
Expand Down Expand Up @@ -258,6 +263,17 @@ void qtWeatherStations::showStations()
this->UI->StationText->setText("Retrieving station data.");
// Todo is there any way to update StationText (QTextEdit) *now* ???

// remove old markers
// testing DeleteMarker
for (const auto& id : StationMap)
{
if (!this->MapMarkers->DeleteMarker(id.first))
{
std::cout << "Error: unable to delete marker "
<< id.first << std::endl;
}
}
//this->MapMarkers->DeleteAllMarkers();
this->StationMap.clear();

// Request weather station data
Expand Down Expand Up @@ -329,10 +345,10 @@ Json::Value qtWeatherStations::RequestStationData()
// Construct openweathermaps request
int count = this->UI->StationCountSpinBox->value();
const char* appId = "14cdc51cab181f8848f43497c58f1a96";
const char* format = "http://api.openweathermap.org/data/2.5/find"
"?lat=%f&lon=%f&cnt=%d&units=imperial&APPID=%s";
char url[256];
sprintf(url, format, lat, lon, count, appId);
snprintf(url, 256, "http://api.openweathermap.org/data/2.5/find"
"?lat=%f&lon=%f&cnt=%d&units=imperial&APPID=%s",
lat, lon, count, appId);
std::cout << "url " << url << std::endl;

// Initialize curl & send request
Expand All @@ -342,17 +358,18 @@ Json::Value qtWeatherStations::RequestStationData()

std::stringstream curlStream;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &curlStream);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "wsmap");

//curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
//std::cout << "Start request" << std::endl;
// Use blocking IO for now
CURLcode res = curl_easy_perform(curl);
curl_easy_perform(curl);
//std::cout << "Request end, return value " << res << std::endl;
curl_easy_cleanup(curl);

// Parse input string (json)
curlStream.seekp(0L);
std::string curlData = curlStream.str();
//std::string curlData = curlStream.str();
//std::cout << curlData << std::endl;

Json::Reader reader;
Expand Down Expand Up @@ -381,7 +398,7 @@ std::vector<StationReport> qtWeatherStations::ParseStationData(Json::Value json)
return stationList;
}

for (int i = 0; i < stationListNode.size(); ++i)
for (int i = 0; i < int(stationListNode.size()); ++i)
{
StationReport station;

Expand Down Expand Up @@ -422,7 +439,7 @@ void qtWeatherStations::DisplayStationData(
std::vector<StationReport> stationList)
{
std::stringstream ss;
for (int i = 0; i < stationList.size(); ++i)
for (size_t i = 0; i < stationList.size(); ++i)
{
StationReport station = stationList[i];
ss << std::setw(3) << i + 1 << ". " << station.id << " " << std::setw(20)
Expand All @@ -449,7 +466,7 @@ void qtWeatherStations::DisplayStationMarkers(
std::vector<StationReport> stationList)
{
// Create map markers for each station
for (int i = 0; i < stationList.size(); ++i)
for (size_t i = 0; i < stationList.size(); ++i)
{
StationReport station = stationList[i];
vtkIdType id =
Expand Down
2 changes: 1 addition & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ target_include_directories(vtkMapCore
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE
${CURL_INCLUDE_DIRS}
PRIVATE
${OPENGL_INCLUDE_DIRS}
)

Expand Down
2 changes: 1 addition & 1 deletion core/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Timer

void reset() { timestamp = std::chrono::high_resolution_clock::now(); }

template <typename Period>
template<typename Period>
size_t elapsed()
{
const auto current = std::chrono::high_resolution_clock::now();
Expand Down
8 changes: 6 additions & 2 deletions core/vtkFeature.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ vtkProp* vtkFeature::PickProp()
}

//----------------------------------------------------------------------------
void vtkFeature::PickItems(
vtkRenderer* renderer, int displayCoords[4], vtkGeoMapSelection* selection)
void vtkFeature::PickItems(vtkRenderer* renderer,
int displayCoords[4],
vtkGeoMapSelection* selection)
{
(void) renderer;
(void) displayCoords;
(void) selection;
vtkWarningMacro("vtkFeature::PickItems() called -- should be overridden in "
<< this->GetClassName());
}
5 changes: 3 additions & 2 deletions core/vtkFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ class VTKMAPCORE_EXPORT vtkFeature : public vtkObject
// Description:
// Pick all feature items at designated display coordinates.
// For external features to override.
virtual void PickItems(
vtkRenderer* renderer, int displayCoords[4], vtkGeoMapSelection* selection);
virtual void PickItems(vtkRenderer* renderer,
int displayCoords[4],
vtkGeoMapSelection* selection);

protected:
vtkFeature();
Expand Down
50 changes: 21 additions & 29 deletions core/vtkFeatureLayer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ vtkStandardNewMacro(vtkFeatureLayer);
class vtkFeatureLayer::vtkInternal
{
public:
std::vector<vtkFeature*> Features;
std::vector<vtkSmartPointer<vtkFeature>> Features;
vtkSmartPointer<vtkCollection> FeatureCollection;

vtkInternal()
Expand All @@ -46,9 +46,7 @@ vtkFeatureLayer::vtkFeatureLayer()
}

//----------------------------------------------------------------------------
vtkFeatureLayer::~vtkFeatureLayer()
{
}
vtkFeatureLayer::~vtkFeatureLayer() {}

//----------------------------------------------------------------------------
void vtkFeatureLayer::PrintSelf(std::ostream& os, vtkIndent indent)
Expand All @@ -61,11 +59,11 @@ void vtkFeatureLayer::PrintSelf(std::ostream& os, vtkIndent indent)
}

//----------------------------------------------------------------------------
void vtkFeatureLayer::Delete()
void vtkFeatureLayer::UnRegister(vtkObjectBase* o)
{
if (this->GetReferenceCount() > 1)
{
this->Superclass::Delete();
this->Superclass::UnRegister(o);
return;
}

Expand All @@ -75,20 +73,18 @@ void vtkFeatureLayer::Delete()
for (std::size_t i = 0; i < size; ++i)
{
//invoke delete on each vtk class in the vector
vtkFeature* f = this->Impl->Features[i];
if (f)
if (this->Impl->Features[i])
{
f->CleanUp();
f->Delete();
this->Impl->Features[i]->CleanUp();
}
}
delete this->Impl;

this->Superclass::Delete();
this->Superclass::UnRegister(o);
}

//----------------------------------------------------------------------------
void vtkFeatureLayer::AddFeature(vtkFeature* feature)
void vtkFeatureLayer::AddFeature(vtkSmartPointer<vtkFeature> feature)
{
if (!feature)
{
Expand All @@ -105,45 +101,41 @@ void vtkFeatureLayer::AddFeature(vtkFeature* feature)
return;
}

std::vector<vtkFeature*>::iterator itr = std::find(
auto itr = std::find(
this->Impl->Features.begin(), this->Impl->Features.end(), feature);
if (itr == this->Impl->Features.end())
{
feature->Register(this);
feature->SetLayer(this);
this->Impl->Features.push_back(feature);
}

feature->Init();

// Notify the map
this->Map->FeatureAdded(feature);
this->Map->FeatureAdded(feature.GetPointer());

this->Modified();
}

//----------------------------------------------------------------------------
void vtkFeatureLayer::RemoveFeature(vtkFeature* feature)
void vtkFeatureLayer::RemoveFeature(vtkSmartPointer<vtkFeature> feature)
{
if (!feature)
{
return;
}

// Notify the map first
this->Map->ReleaseFeature(feature);

feature->CleanUp();
typedef std::vector<vtkFeature*>::iterator iter;
iter found_iter = std::find(
auto found_iter = std::find(
this->Impl->Features.begin(), this->Impl->Features.end(), feature);
if (found_iter != this->Impl->Features.end())
{
// Notify the map first
this->Map->ReleaseFeature(feature.GetPointer());

//now that we have found the feature delete it, leaving a dangling pointer
(*found_iter)->Delete();
feature->CleanUp();

//now resize the array to not hold the empty feature
this->Impl->Features.erase(std::remove(
this->Impl->Features.begin(), this->Impl->Features.end(), feature));
this->Impl->Features.erase(found_iter);
}
}

//----------------------------------------------------------------------------
Expand All @@ -152,10 +144,10 @@ vtkCollection* vtkFeatureLayer::GetFeatures()
// The internal feature collection could be cached, but for,
// we'll rebuild it every time.
this->Impl->FeatureCollection->RemoveAllItems();
std::vector<vtkFeature*>::iterator iter = this->Impl->Features.begin();
auto iter = this->Impl->Features.begin();
for (; iter != this->Impl->Features.end(); iter++)
{
vtkFeature* feature = *iter;
vtkFeature* const feature = iter->GetPointer();
this->Impl->FeatureCollection->AddItem(feature);
}
return this->Impl->FeatureCollection;
Expand Down
8 changes: 4 additions & 4 deletions core/vtkFeatureLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ class VTKMAPCORE_EXPORT vtkFeatureLayer : public vtkLayer
vtkTypeMacro(vtkFeatureLayer, vtkLayer)

// Description:
// Override vtkObject::Delete()
// Override vtkObjectBase::UnRegister(vtkObjectBase*)
// Needed in order to delete features, which use a weak pointer to
// to their vtkFeatureLayer instance,
void Delete() override;
void UnRegister(vtkObjectBase* o) override;

// Description:
// Add a new feature to the layer
// Note: layer must be added to a vtkMap *before* features can be added.
void AddFeature(vtkFeature* feature);
void AddFeature(vtkSmartPointer<vtkFeature> feature);

// Description:
// Remove a feature from the layer
void RemoveFeature(vtkFeature* feature);
void RemoveFeature(vtkSmartPointer<vtkFeature> feature);

// Description:
// Return all features contained here
Expand Down
Loading