I want to slice horizontal contour lines through a geometry similar to the process described in this post - How to create latitudinal (horizontal) contour lines in GLSL?
I'm doing this with WebGL, and it seems that "fwidth" is only available for OpenGL. Is there an available workaround so that I can get the anti-aliasing from fwidth on the web?
The fwidth function is available using WebGL, you just have to use the OES_standard_derivatives extension by running:
var ext = gl.getExtension("OES_standard_derivatives");
if (!ext) {
// tell user they can't use your site or provide
// other fallback
}
Related
I'm using the Qt C++ ArcGIS Runtime SDK v100.9 and I have various shapes and labels being drawn on a map.
I want to be able to find out the area (bounding rectangle) of Graphic (which is a text label (TextSymbol) at a given point (SpatialReference::wgs84) on the map) so I can determine if the width of the label is more or less than another Graphic (lets say it has a Polygon for its Geometry which is being used to draw a circle) in order to decide if the label should be set to visible or not.
Within a class derived from Esri::ArcGISRuntime::MapGraphicsView the circle and the text label are created along the lines of:
Point centerWgs84(0.0, 0.0, SpatialReference::wgs84());
Graphic* circleGraphic_p = new Graphic(GeometryEngine::bufferGeodetic(centerWgs84, 1000.0, LinearUnit::meters(), 0.5, GeodeticCurveType::Geodesic));
this->graphicsOverlays()->at(0)->graphics()->append(circleGraphic_p);
circleGraphic_p->setSymbol(new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor(Qt::blue), 1.0));
circleGraphic_p->setVisible(true);
TextSymbol* textMarker_p = new TextSymbol("Some Label", Qt::black, 12.0, HorizontalAlignment::Center, VerticalAlignment::Bottom);
Graphic* labelGraphic_p = new Graphic(centerWgs84, textMarker_p);
this->graphicsOverlays()->at(0)->graphics()->append(labelGraphic_p);
labelGraphic_p->setVisible(true);
Rather than always setting the label visibility to true, I thought I would be able to take the Geometry of each Graphic and use it to construct an Envelope which would allow me to then get the width of each envelope that could then be compared:
Envelope circleEnvelope(circleGraphic_p->geometry());
Envelope labelEnvelope(labelGraphic_p->geometry());
labelGraphic_p->setVisible(circleEnvelope.width() >= labelEnvelope.width());
but when I try and do this, the width of each envelope is always a very small negative value (such as -2.25017... e-98)
Any suggestions on what I am doing wrong or if there is a better way to get the size on the map (or in device independent units) of the text label and a Graphic described by the Geometry of a Polyline or Polygon?
EDIT: I've discovered that the Geometry object has an extent() method from which I can get the width of the circle but the Geometry of the Graphic being used for the text label results in a width of zero from its extent() method. I expect this is because the Geometry is just a Point which has no width or height. So the question still stands of how to get the bounding rectangle of a TextSymbol?
You are correct, the extent is being returned of the underlying geometry, not the TextSymbol. I don't think you will be able to achieve what you are wanting in the way you are going about it, as there isn't a way to get the bounding box or screen coordinates of the symbol itself. Instead, have you considered using LabelDefinitions and setting the various deconfliction options? This sample shows labels on layers, but can be applied to graphics as well. There are many labeling options you can apply, and this would allow the internal labeling engine to deconflict for you.
According to my recollection, once an object or a scene was described in PovRay, there was no other output than the rendering generated. In other words, once exported into *.pov, you were no longer able to convert it into an other 3D file format.
Hence I was very surprised to learn about pov2mesh that aims to generate a point cloud, thanks to meshlab eventually suitable for 3D printing.
As I have a number of scenes defined only as *.pov describing molecules (so, spheres and sticks) and colour encoded molecular surfaces from computation, I wonder if there were a way to convert / rewrite such a scene into a format like vrml 2.0, preserving both shape and colour of them.
Performing the computation again and saving the result straight ahead as vrml is not an option, as beside binary output understood by the software, the choice to save the results is either *.png, or *.pov.
Or is there a povray editor, that is able to understand a *.pov produced by other software, and offeres to export the scene in *.vrml (or a different 3D file format)?
I don't think there is an editor that converts from .pov to .vrml, but both formats are text based. Since your pov file is only made out of sphere and cylinders you could convert it by hand, or write a simple program to do it for you. Here is a red sphere in Povray (http://www.povray.org/documentation/view/3.6.2/283/)
sphere{
<0, 0, 0>, 1
pigment{
color rgb <1, 0, 0>
}
}
I don't know much about vrml but this should be the equivalent (found here: https://www.siggraph.org/special-projects/com97/vrmlexample1.html)
Shape {
appearance Appearance {
material Material {
diffuseColor 1.0 0.0 0.0
transparency 0.0
}
}
geometry Sphere {
radius 1.0
}
}
I created a rounded rectangle on illustrator and export in to png , then added this image to texturepacker and import to cocos2d here is my rectangle,
Have you any idea why there are white pixels on the corner.
Here is image https://dl.dropboxusercontent.com/u/9018754/Screen%20Shot%202014-07-31%20at%2023.28.52.png
Might be that the image was written as png8 with blending towards a white background in Illustrator.
Can you also post the png you created from Illustrator?
-- update --
The image looks fine. I think we can rule out problems with exporting the image.
In your settings "Premultiply Alpha" is off. When importing the image into cocos2d, did you enabled premultipled alpha?
Both values must be matching. Otherwise you will get some strange behaviour.
If it's on in TexturePacker and off in cocos2d you get black outlines.
If it's off in TexturePacker and on in cocos2d you get white outlines.
So: Try enabling it in TexturePacker.
Yes Premultiply Alpha solved my problem
Changing ccConfig.h to
#ifndef CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
#define CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL 1
#endif
and setting premultiply alpha + exclude 1 solved my problem ,
It is written in the comment line
**
` If enabled, the texture coordinates will be calculated by using this formula:
- texCoord.left = (rect.origin.x*2+1) / (texture.wide*2);
- texCoord.right = texCoord.left + (rect.size.width*2-2)/(texture.wide*2);
The same for bottom and top.
This formula prevents artifacts by using 99% of the texture.
The "correct" way to prevent artifacts is by using the spritesheet-artifact-fixer.py or a similar tool.
Affected nodes:
- CCSprite / CCSpriteBatchNode and subclasses: CCLabelBMFont, CCTMXLayer
- CCLabelAtlas
- CCParticleSystemQuad
- CCTileMap
To enabled set it to 1. Disabled by default.
**
I couldnt figure out what is going on at the moment but I will check code deeper ,
Thank you Andreas Löw
I’m trying to develop (using C++ - MSVS 12.0) a function that discover which pixels (from a raster image) have its center inside a polygon (previously populated using a shapefile). I’m using GDAL 1.11.0 (just installed, using devinstall) building from source and using the option INCLUDE_OGR_FRMTS=YES. I can use GDAL and most of OGR functions without problem. However, when I use the following code:
if (polygon->Contains(tmpPoint))
I receive the error message: ERROR 6: GEOS support not enabled
Anybody knows how to solve this issue?
I’m using:
#include "ogrsf_frmts.h"
and my function is declared:
void FindPixels(GDALDataset *image, OGRLayer *poLayer, OGRPolygon *polygon)
and part of my code is:
OGRPoint *tmpPoint = NULL
OGRSpatialReference *spatialReference = NULL;
spatialReference = polygon->getSpatialReference();
tmpPoint = new OGRPoint();
tmpPoint->assignSpatialReference(spatialReference);
loop begin:
tmpPoint->setX(imgTLX + (j * imgRes) + imgResHalf);
tmpPoint->setY(imgTLY - (i * imgRes) - imgResHalf);
if (polygon->Contains(tmpPoint))
Thanks in advance!
MB
Use GDALRasterizeLayers to burn the image of polygon onto a raster. This way you will find all the pixels that fall into the polygon, or not. The default is to burn the pixel only if the centre intersects a polygon.
If the source layer has multiple polygons, you may need to distinguish them by either setting an attribute filter, or using burned attribute ID fields (although this won't work if the polygons overlap).
I am creating a simple 2D OpenGL game, and I need to know when the player clicks or mouses over an OpenGL primitive. (For example, on a GL_QUADS that serves as one of the tiles...) There doesn't seems to be a simple way to do this beyond brute force or opengl.org's suggestion of using a unique color for every one of my primitives, which seems a little hacky. Am I missing something? Thanks...
My advice, don't use OpenGL's selection mode or OpenGL rendering (brute force method you are talking about), use a CPU-based ray picking algorithm if 3D. For 2D, like in your case, it should be straightforward, it's just a test to know if a 2D point is in a 2D rectangle.
I would suggest to use the hacky method if you want a quick implementation (coding time, I mean). Especially if you don't want to implement a quadtree with moving ojects. If you are using opengl immediate mode, that should be straightforward:
// Rendering part
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
for(unsigned i=0; i<tileCout; ++i){
unsigned tileId = i+1; // we inc the tile ID in order not to pick up the black
glColor3ub(tileId &0xFF, (tileId >>8)&0xFF, (tileId >>16)&0xFF);
renderTileWithoutColorNorTextures(i);
}
// Let's retrieve the tile ID
unsigned tileId = 0;
glReadPixels(mouseX, mouseY, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
(unsigned char *)&tileId);
if(tileId!=0){ // if we didn't picked the black
tileId--;
// we picked the tile number tileId
}
// We don't want to show that to the user, so we clean the screen
glClearColor(...); // the color you want
glClear(GL_COLOR_BUFFER_BIT);
// Now, render your real scene
// ...
// And we swap
whateverSwapBuffers(); // might be glutSwapBuffers, glx, ...
You can use OpenGL's glRenderMode(GL_SELECT) mode. Here is some code that uses it, and it should be easy to follow (look for the _pick method)
(and here's the same code using GL_SELECT in C)
(There have been cases - in the past - of GL_SELECT being deliberately slowed down on 'non-workstation' cards in order to discourage CAD and modeling users from buying consumer 3D cards; that ought to be a bad habit of the past that ATI and NVidia have grown out of ;) )