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

Ensure hoels of polygons have correct handedness #3139

Merged
merged 1 commit into from
Apr 21, 2020
Merged

Conversation

PaulWessel
Copy link
Member

Do not trust the incoming data. For polygons with holes that need to be filled, we ensure the holes have a different handedness than the parent, reversing the child if needed. Closes #3135.

Do not trust the incoming data.  For polygons with holes that need to be filled, we ensure the holes have a different handedness than the parent, reversing the child if needed.  Closes #3135.
@joa-quim
Copy link
Member

joa-quim commented Apr 21, 2020

OK, this works but there is some other bug from externals that probably is not looking for the -Ph option.
This paints the hole in blue

> -Gred
0  0
5  0
5  10
0  10
0  0
> -Ph -Gblue
2  1
2  3
4  3
4  1
2  1

D = gmtread("quad.dat");
plot(D, J="X12c", B="a2f1WSen", W=1, show=1)

but does not make it transparent when I remove the -Gblue from second segment header. So -Ph is in fact ignored.
It does, however, work fine when I don't read the data before hand and let GMT do it. That is, this works

plot("quad.dat", J="X12c", B="a2f1WSen", W=1, show=1)

@PaulWessel
Copy link
Member Author

Maybe make a mex version of the test?

@PaulWessel PaulWessel merged commit 48b54bc into master Apr 21, 2020
@PaulWessel PaulWessel deleted the orient-holes branch April 21, 2020 18:07
@joa-quim
Copy link
Member

Use your Julia. Life is much easier with it

D=gmtmex('read quad.dat -Td');
gmtmex('psxy -JX12c -Ba2f1WSen -W1 -R-0.5/10.5/-0.5/10.5 > lixo.ps', D)

@PaulWessel
Copy link
Member Author

OK, fine. I just installed/update julia to 1.3.1. Followed your macOS hint of addint startup.jl. Then tried ]add GMT and ERROR unexpected ].

@PaulWessel
Copy link
Member Author

Am I completely missing any instructions for actuallly installing GMT.jl?.

@joa-quim
Copy link
Member

Last version is Julia 1.4 but 1.3 is just as good.
You only have to do
] add GMT
When you type the ] the prompt immediately turns into pkg. What is your ERROR unexpected``?

@PaulWessel
Copy link
Member Author

Seems like your instructions is missing some critical spaces between ] and add. Works now.

@joa-quim
Copy link
Member

Ah, because you copy-pasted?

@PaulWessel
Copy link
Member Author

Yes, but also the README.md has no space.

@PaulWessel
Copy link
Member Author

Now here:
ia> D = gmtread("quad.dat");
ERROR: UndefVarError: gmtread not defined

@PaulWessel
Copy link
Member Author

FYI, the adding package seems to work?

v1.3) pkg>  add GMT
   Cloning default registries into `~/.julia`
   Cloning registry from "https://github.com/JuliaRegistries/General.git"
     Added registry `General` to `~/.julia/registries/General`
 Resolving package versions...
 Installed GMT ─ v0.17.0
  Updating `~/.julia/environments/v1.3/Project.toml`
  [5752ebe1] + GMT v0.17.0
  Updating `~/.julia/environments/v1.3/Manifest.toml`
  [5752ebe1] + GMT v0.17.0
  [de0858da] + Printf 
  [4ec0a83e] + Unicode 

@joa-quim
Copy link
Member

joa-quim commented Apr 21, 2020

Ok, you should not need it but better to have the master version
] add GMT#master
And more thing, you have to do
D = gmtread("/path/to/file"); or do a cd("/path/to/file) first.
But you say gmtread is not found? Can't be. Try running the tests
] test GMT

@joa-quim
Copy link
Member

Ah sorry, I know. It's like Python. Before using any package you have to import it. So first command per session has to be
using GMT

@PaulWessel
Copy link
Member Author

D = gmtread("quad.dat");
ERROR: error compiling gmtread: error compiling #gmtread#60: error compiling gmt: could not load library "libgmt"

I put the startup.jp in config with path to my library dir and restarted.

julia
ERROR: LoadError: UndefVarError: Libdl not defined

@joa-quim
Copy link
Member

Ok the other user that passed through this had to do
using Libdl before the push!(Libdl.DL_LOAD_PATH ...
I have to update this instructions also

@PaulWessel
Copy link
Member Author

I added a call to Libdl in startup.jo before the LIB call. Same error.
Admittedly I am a Julia rookie so this is a very good test - clearly your README needs some work. I would think the average rookie would give up by now.

@PaulWessel
Copy link
Member Author

OK, using Libdl works.
Plot generated.

@joa-quim
Copy link
Member

Good. I debugged to confirm that the header is well transmitted to GMT. And mex version confirms the same thing. No hole.

@PaulWessel
Copy link
Member Author

So when I debug MEX I have to load in gmtmex.c (compiled for Xcode) into Xcode, set a stop point, start matlab, connect Xcode to MATLAB processes, then run the matlab command.
What do I load into Xcode to set a stop point for Julia???

@PaulWessel
Copy link
Member Author

You may need to add a "how to debug" section.

@PaulWessel
Copy link
Member Author

Anyway, in the GMT io we do this:

if (gmt_parse_segment_item (GMT, S->header, "-Ph", NULL)) SH->pol_mode = GMT_IS_HOLE;

so the hidden helper structure per segment sets a flag. When gmt read returns to mablat it has the info:

ans = 

  struct with fields:

       data: [5x2 double]
       text: []
     header: '-Gred'
    comment: []
      proj4: []
        wkt: []

>> D(2)

ans = 

  struct with fields:

       data: [5x2 double]
       text: []
     header: '-Ph'
    comment: []
      proj4: []
        wkt: []

What does your Julia D data have?

@joa-quim
Copy link
Member

Ok, dinner time here (still preparing it).
To debug from Julia you should do exactly the same but load the Julia process in Xcode. There is no equivalent in C to gmtmex so you can't debug that part with Xcode (you need VScode).

In Julia you get the same thing as in Matlab . Have a function for display that only shows first segment. To see more you do

julia> D[1]
Header: -Gred
5×2 Array{Float64,2}:
 0.0   0.0
 5.0   0.0
 5.0  10.0
 0.0  10.0
 0.0   0.0


julia> D[2]
Header: -Ph -Gblue
5×2 Array{Float64,2}:
 2.0  1.0
 2.0  3.0
 4.0  3.0
 4.0  1.0
 2.0  1.0

@PaulWessel
Copy link
Member Author

As far as I can tell, when D is passed back into a matlab gmt call the header is extracted and copied into the GMT segment header so it should work - I just need to rebuild gmtmex here.

@joa-quim
Copy link
Member

I verified that it is indeed like that from Julia, but -Ph makes no effect (tried with both -Ph -Gblue and -Ph

@joa-quim
Copy link
Member

joa-quim commented Apr 21, 2020

Don't want to try a debug from Julia?

  1. Load the Julia process in XCode
  2. Open a GMT source code in XCode and set a breakpoint
  3. run the julia command that triggers that breakpoint

Ofc never tried in Mac but that's what I do on Windows.

@PaulWessel
Copy link
Member Author

OK, it makes sense to set stop point in the GMT C in Xcode. I will see - as you know multi-tasking on this end during the day...

@joa-quim
Copy link
Member

BTW, I updated the installing instructions so you can give a star to the project.

PaulWessel added a commit that referenced this pull request Apr 23, 2020
* doc: Fix references to GMT defaults (#3132)

* Auto-generate gmt_moduleinfo.h

* Fix new bug in filterwidth parsing for median filter (#3137)

I recently introduced this bug.

* Better check if no barwidth given in -D (#3138)

With nothing we are thrown into the deprecated parsing and it did not check if nothing was given.  Closes #3136.

* Ensure hoels of polygons have correct handedness (#3139)

Do not trust the incoming data.  For polygons with holes that need to be filled, we ensure the holes have a different handedness than the parent, reversing the child if needed.  Closes #3135.

* Make info go to GMT_MSG_INFORMATION

* Fix extending the grid in grdcut (#3142)

* Fix extending the grid in grdcut

When grdcut -N is used we can extend the grid beyond its domain and fill in the new areas with NaNs.  However, if the new region was not kosher and changed the domain by an integer number of pixels our algorithm for filling in NaNs got tricked and the result was a new grid with a bunch of zero nodes.  This PR checks for this case and adds a sanity check as well.

* Update grdcut.c

* Remember to also flip curves with -N with -A is used (#3145)

Needed to flip the x and y coordinates when plotting the pdf curves when -A is used.  Closes #3141.

* Fix wrong string comparison when converting berween GMT and GDAL ellipsoid names (#3143)

* Let set_tbl_minmax make hole connections (#3146)

Since datasets may come to us via external interfaces we need to look for polygons with holes and hook things up.

* Major revision of grd2kml (#3144)

* Update grd2kml.c

Fix the quadtree.

* Update grdvector_common.rst_

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* FInalize module

* Remove junk update docs

* Update grd2kml.c

* Add -S option

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Allow JPGs vs PNGs

* Eliminate -Q

* Handle grdiline grids

* Fix both grdcut and grd2kml use of it.

* Fix contours

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Allow variable pen widths

It is best to scale down pen widthd for lower levels as otherwise they are just too thick.

* Let pen scale/limit be set via modifier +s

* Same -A as gmt2kml

* Update grdcontour.c

* Fix my bug in grdcontour (#3149)

I forgot to set the id of the pen before using it...

* Limit -J to x|X for histogram (#3148)

It currently prints out all the map projections.  Closes #3140.

* Relegate no contour message back to information (#3150)

This was elevated back when -V was required to get any information at all.  Since warnings are now default, we move this to information.  I also added the same information message to pscontour.

* Add the missing entries

Co-authored-by: Paul Wessel <[email protected]>
Co-authored-by: Joaquim Luis <[email protected]>
PaulWessel added a commit that referenced this pull request Apr 25, 2020
* Eliminate duplications

* Add title

* Update gmt_core_module.c

* Redo everything

* Update CMakeLists.txt

* names...

* Update gmt_api.c

* Update src/CMakeLists.txt

Co-Authored-By: Dongdong Tian <[email protected]>

* Update CMakeLists.txt

* Update gmt_modules.h

* Only shared libraries supported

* Eliminate function pointer in struct

* Change common_*.[ch] to gmt_*.[ch]

* Auto-generate gmt_moduleinfo.h (#3134)

* doc: Fix references to GMT defaults (#3132)

* Auto-generate gmt_moduleinfo.h

* Fix new bug in filterwidth parsing for median filter (#3137)

I recently introduced this bug.

* Better check if no barwidth given in -D (#3138)

With nothing we are thrown into the deprecated parsing and it did not check if nothing was given.  Closes #3136.

* Ensure hoels of polygons have correct handedness (#3139)

Do not trust the incoming data.  For polygons with holes that need to be filled, we ensure the holes have a different handedness than the parent, reversing the child if needed.  Closes #3135.

* Make info go to GMT_MSG_INFORMATION

* Fix extending the grid in grdcut (#3142)

* Fix extending the grid in grdcut

When grdcut -N is used we can extend the grid beyond its domain and fill in the new areas with NaNs.  However, if the new region was not kosher and changed the domain by an integer number of pixels our algorithm for filling in NaNs got tricked and the result was a new grid with a bunch of zero nodes.  This PR checks for this case and adds a sanity check as well.

* Update grdcut.c

* Remember to also flip curves with -N with -A is used (#3145)

Needed to flip the x and y coordinates when plotting the pdf curves when -A is used.  Closes #3141.

* Fix wrong string comparison when converting berween GMT and GDAL ellipsoid names (#3143)

* Let set_tbl_minmax make hole connections (#3146)

Since datasets may come to us via external interfaces we need to look for polygons with holes and hook things up.

* Major revision of grd2kml (#3144)

* Update grd2kml.c

Fix the quadtree.

* Update grdvector_common.rst_

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* FInalize module

* Remove junk update docs

* Update grd2kml.c

* Add -S option

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Allow JPGs vs PNGs

* Eliminate -Q

* Handle grdiline grids

* Fix both grdcut and grd2kml use of it.

* Fix contours

* Update grd2kml.c

* Update grd2kml.c

* Update grd2kml.c

* Allow variable pen widths

It is best to scale down pen widthd for lower levels as otherwise they are just too thick.

* Let pen scale/limit be set via modifier +s

* Same -A as gmt2kml

* Update grdcontour.c

* Fix my bug in grdcontour (#3149)

I forgot to set the id of the pen before using it...

* Limit -J to x|X for histogram (#3148)

It currently prints out all the map projections.  Closes #3140.

* Relegate no contour message back to information (#3150)

This was elevated back when -V was required to get any information at all.  Since warnings are now default, we move this to information.  I also added the same information message to pscontour.

* Add the missing entries

Co-authored-by: Paul Wessel <[email protected]>
Co-authored-by: Joaquim Luis <[email protected]>

* cmake: Simplify the regex for building gmt_moduleinfo.h (#3153)

* Eliminate old gmt_supplements_module.[ch]

Made gmt_suppl_glue.[ch].in after gmt_glue.[ch] and gmt_suppl_modules.h after gmt_modules.h and the contents of the old gmt_supplements_module.h.  I include gmt_suppl_modules.h from gmt_dev.h and gmt_suppl_glue.h from gmt_api.c.  I updated the CMakefile to configure the two new files.  All compiles but currently the gmt_suppl_glue.[ch] file says "core" instead of "suppl" in the function names.

* Update src/CMakeLists.txt

Co-Authored-By: Dongdong Tian <[email protected]>

* Update CMakeLists.txt

* Build gmt_suppl_moduleinfo.h (#3154)

* Eliminate gmt_modules.h and gmt_suppl_modules.h

* Update CMakeLists.txt

Need correct name

* Ignore modules.h files

* Add EXTERN_MSC to all module functions

* Build gmt_suppl_moduleinfo.h

* Finalize new api build via Cmake

Local tests run fine on macOS

* Use GMT_SUPPL_LIB_NAME Cmake variable instead of hardwired "supplements"

* Update cmake/ConfigDefault.cmake

Co-Authored-By: Dongdong Tian <[email protected]>

* Eliminate glue include files (#3159)

* Eliminate glue include files

Since the glue functions are not called as is anywhere, their names are only assembled via strings and obtained via a pointer from dlsym, there is no purpose to gmt_glue.h and gmt_suppl_glue.h.  Just added EXTERN_MSC to the functions in gmt_*glue.c instead.

* Eliminate suppl_glue in repo

* Update comments for BUILD_SHARED_LIBRARIES

* remove unused file and macro

* Update CMakeLists.txt

* Delete gmt_make_module_src.sh

* Update CMakeLists.txt

* Update MB-system files

* CI: Remove gmt_make_module_src.sh from CI testing (#3160)

gmt_make_module_src.sh is no longer used and was removed in branch new-api-lookup.

* Update gmt_glue.c.in

* Update gmt_glue.c.in

* Rename Gmt_libinfo struct type to GMT_LIBINFO

Stick with our conventions

* cmake: Extract gmtread and gmtwrite module information from source codes directly (#3163)

* Rename vars (#3164)

* Rename SUPPL_* toSHARED_LIB_*

* Update gmt_glue.c.in

* Update src/CMakeLists.txt

Co-Authored-By: Dongdong Tian <[email protected]>

* More documentation

* Move settings closer to library building

Co-authored-by: Dongdong Tian <[email protected]>

* GMT_SUPPL_LIB_NAME was defined on Windows only (#3166)

* cmake: Make the CMake file more readable (#3167)

Co-authored-by: Dongdong Tian <[email protected]>
Co-authored-by: Joaquim Luis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Polygon holes filling is tricky
2 participants