Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/topic/label-wrapup'
Browse files Browse the repository at this point in the history
  • Loading branch information
mousebird committed Apr 1, 2021
2 parents 5eb32a1 + 2bca613 commit ffffff1
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 59 deletions.
2 changes: 1 addition & 1 deletion common/WhirlyGlobeLib/include/LinearTextBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class LinearWalker {

/// Calculate the next point along the line given the distance
/// Or return false if there wasn't anything left
bool nextPoint(double distance,Point2f *retPt,Point2f *norm,bool savePos=true);
bool nextPoint(double distance,Point2f *retPt=nullptr,Point2f *norm=nullptr,bool savePos=true);

protected:
VectorRing pts;
Expand Down
18 changes: 10 additions & 8 deletions common/WhirlyGlobeLib/include/ScreenSpaceBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ScreenSpaceBuilder
/// Add a single screen space object
void addScreenObject(const ScreenSpaceObject &screenObject,
const Point3d &worldLoc,
const std::vector<ScreenSpaceConvexGeometry> &geoms,
const std::vector<ScreenSpaceConvexGeometry> *geoms,
const std::vector<Eigen::Matrix3d> *places = nullptr);

/// Return the drawables constructed. Caller responsible for deletion.
Expand Down Expand Up @@ -178,20 +178,22 @@ class ScreenSpaceBuilder
class ScreenSpaceConvexGeometry
{
public:
ScreenSpaceConvexGeometry();
EIGEN_MAKE_ALIGNED_OPERATOR_NEW;

ScreenSpaceConvexGeometry() = default;

/// Texture ID used for just this object
std::vector<SimpleIdentity> texIDs;
/// Program ID used to render this geometry
SimpleIdentity progID;
SimpleIdentity progID = EmptyIdentity;
/// Color for the geometry
RGBAColor color;
RGBAColor color = RGBAColor::white();
/// Draw order
int64_t drawOrder;
int64_t drawOrder = BaseInfo::DrawOrderTiles;
/// Draw priority
int drawPriority;
int drawPriority = -1;
/// Render target
SimpleIdentity renderTargetID;
SimpleIdentity renderTargetID = EmptyIdentity;
/// Vertex attributes applied to this piece of geometry
SingleVertexAttributeSet vertexAttrs;

Expand Down Expand Up @@ -247,7 +249,7 @@ class ScreenSpaceObject : public Identifiable

void addGeometry(const ScreenSpaceConvexGeometry &geom);
void addGeometry(const std::vector<ScreenSpaceConvexGeometry> &geom);
std::vector<ScreenSpaceConvexGeometry> getGeometry() const { return geometry; }
const std::vector<ScreenSpaceConvexGeometry> *getGeometry() const { return &geometry; }

// Get a program ID either from the drawable state or geometry
SimpleIdentity getTypicalProgramID();
Expand Down
55 changes: 28 additions & 27 deletions common/WhirlyGlobeLib/src/LayoutManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,10 @@ bool LayoutManager::runLayoutRules(PlatformThreadInfo *threadInfo,
// wkLog("----");

for (auto layoutObj : container.objs) {
layoutObj->newEnable = false;
layoutObj->obj.layoutModelPlaces.clear();
layoutObj->obj.layoutPlaces.clear();

// Layout along a shape
if (!layoutObj->obj.layoutShape.empty()) {
// Sometimes there are just a few instances
Expand All @@ -646,7 +650,7 @@ bool LayoutManager::runLayoutRules(PlatformThreadInfo *threadInfo,
std::vector<Point3d> layoutModelInstances;

auto runs = textBuilder.getScreenVecs();
// unsigned int ri=0;
unsigned int ri=0;
for (auto run: runs) {
// wkLog("Run %d",ri++);

Expand All @@ -672,8 +676,9 @@ bool LayoutManager::runLayoutRules(PlatformThreadInfo *threadInfo,

// Center around the world point on the screen
Point2f midRun;
if (!walk.nextPoint(layoutMbr.span().x()/2.0, &midRun, nullptr, false))
if (!walk.nextPoint(resScale * layoutMbr.span().x()/2.0, &midRun, nullptr, false))
continue;
// wkLogLevel(Info, "midRun = (%f,%f)",midRun.x(),midRun.y());
Point2f worldScreenPt = midRun;
Point3d worldPt(0.0,0.0,0.0);
if (!textBuilder.screenToWorld(midRun, worldPt))
Expand Down Expand Up @@ -711,36 +716,34 @@ bool LayoutManager::runLayoutRules(PlatformThreadInfo *threadInfo,

// Translate the glyph into that position
Affine2d transPlace(Translation2d((centerPt.x()-worldScreenPt.x())/2.0,
-(centerPt.y()-worldScreenPt.y())/2.0));
(worldScreenPt.y()-centerPt.y())/2.0));
double ang = -1.0 * (atan2(norm.y(),norm.x()) - M_PI/2.0);
Matrix2d screenRot = Eigen::Rotation2Dd(ang).matrix();
Matrix3d screenRotMat = Matrix3d::Identity();
for (unsigned ix=0;ix<2;ix++)
for (unsigned iy=0;iy<2;iy++)
screenRotMat(ix, iy) = screenRot(ix, iy);
Matrix3d overlapMat = transPlace.matrix() * screenRotMat * transOrigin.matrix();
Matrix3d scaleMat = Eigen::AlignedScaling3d(resScale,resScale,1.0);
Matrix3d overlapMat = transPlace.matrix() * screenRotMat * scaleMat * transOrigin.matrix();
// Matrix3d overlapMat = transPlace.matrix() * transOrigin.matrix();
layoutMats.push_back(transPlace.matrix() * screenRotMat * transOrigin.matrix());
// layoutMats.push_back(transPlace.matrix() * transOrigin.matrix());
Matrix3d testMat = screenRotMat * scaleMat * transOrigin.matrix();
layoutMats.push_back(overlapMat);

// Check for overlap
Point2dVector objPts; objPts.reserve(4);
for (unsigned int oi=0;oi<4;oi++) {
Point3d pt = overlapMat * Point3d(geom.coords[oi].x(),geom.coords[oi].y(),1.0);
Point2d objPt(pt.x()+worldScreenPt.x(),pt.y()+worldScreenPt.y());
Point3d pt = testMat * Point3d(geom.coords[oi].x(),geom.coords[oi].y(),1.0);
Point2d objPt(pt.x()+centerPt.x(),pt.y()+centerPt.y());
objPts.push_back(objPt);
}

// if (!failed) {
// wkLog(" Geometry %d",ig);
// for (unsigned int ip=0;ip<objPts.size();ip++) {
// wkLog(" (%f,%f)",objPts[ip].x(),frameBufferSize.y()-objPts[ip].y());
// wkLog(" (%f,%f)",objPts[ip].x(),objPts[ip].y());
// }
// }

if (!overlapMan.checkObject(objPts)) {
// wkLog(" Failed");
failed = true;
break;
}
Expand All @@ -749,7 +752,7 @@ bool LayoutManager::runLayoutRules(PlatformThreadInfo *threadInfo,
}

if (!failed) {
layoutObj->obj.setRotation(textBuilder.getViewStateRotation());
// layoutObj->obj.setRotation(textBuilder.getViewStateRotation());
layoutModelInstances.push_back(worldPt);
layoutInstances.push_back(layoutMats);
numInstances++;
Expand Down Expand Up @@ -778,9 +781,6 @@ bool LayoutManager::runLayoutRules(PlatformThreadInfo *threadInfo,
layoutObj->offset = Point2d(0.0,0.0);
} else {
isActive = false;
layoutObj->newEnable = false;
layoutObj->obj.layoutPlaces.clear();
layoutObj->obj.layoutModelPlaces.clear();
}

if (layoutObj->currentEnable != isActive) {
Expand Down Expand Up @@ -891,10 +891,10 @@ bool LayoutManager::runLayoutRules(PlatformThreadInfo *threadInfo,
}
}

// wkLogLevel(Debug, "Center pt = (%f,%f), orient = %d",objPt.x(),objPt.y(),orient);
// wkLogLevel(Debug, "Layout Pts");
// for (unsigned int xx=0;xx<objPts.size();xx++)
// wkLogLevel(Debug, " (%f,%f)\n",objPts[xx].x(),objPts[xx].y());
// wkLogLevel(Debug, "Center pt = (%f,%f), orient = %d",objPt.x(),objPt.y(),orient);
// wkLogLevel(Debug, "Layout Pts");
// for (unsigned int xx=0;xx<objPts.size();xx++)
// wkLogLevel(Debug, " (%f,%f)\n",objPts[xx].x(),objPts[xx].y());

// Now try it. Objects we've pegged as essential always win
if (overlapMan.addCheckObject(objPts) || container.importance >= MAXFLOAT)
Expand Down Expand Up @@ -1038,24 +1038,25 @@ void LayoutManager::updateLayout(PlatformThreadInfo *threadInfo,const ViewStateR
//animObj.setDrawOrder(?)
for (auto &geom : animObj.geometry)
geom.progID = params.motionShaderID;
ssBuild.addScreenObject(animObj,animObj.worldLoc,animObj.geometry);
ssBuild.addScreenObject(animObj,animObj.worldLoc,&animObj.geometry);

// And hold off on adding it
// todo: slicing, is this ok?
ScreenSpaceObject shortObj = layoutObj->obj;
//shortObj.setDrawOrder(?)
shortObj.setEnableTime(curTime+params.markerAnimationTime, 0.0);
ssBuild.addScreenObject(shortObj,shortObj.worldLoc,shortObj.geometry);
ssBuild.addScreenObject(shortObj,shortObj.worldLoc,&shortObj.geometry);
} else {
// It's boring, just add it
if (layoutObj->newEnable) {
// It's a single point placement
if (layoutObj->obj.layoutShape.empty())
ssBuild.addScreenObject(layoutObj->obj,layoutObj->obj.worldLoc,layoutObj->obj.geometry);
ssBuild.addScreenObject(layoutObj->obj,layoutObj->obj.worldLoc,&layoutObj->obj.geometry);
else {
// One or more placements along a path
for (unsigned int ii=0;ii<layoutObj->obj.layoutPlaces.size();ii++)
ssBuild.addScreenObject(layoutObj->obj, layoutObj->obj.layoutModelPlaces[ii], layoutObj->obj.geometry, &layoutObj->obj.layoutPlaces[ii]);
for (unsigned int ii=0;ii<layoutObj->obj.layoutPlaces.size();ii++) {
ssBuild.addScreenObject(layoutObj->obj, layoutObj->obj.layoutModelPlaces[ii], &layoutObj->obj.geometry, &layoutObj->obj.layoutPlaces[ii]);
}
}
}
}
Expand Down Expand Up @@ -1092,16 +1093,16 @@ void LayoutManager::updateLayout(PlatformThreadInfo *threadInfo,const ViewStateR
//animObj.setDrawOrder(?)
for (auto &geom : animObj.geometry)
geom.progID = params.motionShaderID;
ssBuild.addScreenObject(animObj, animObj.worldLoc, animObj.geometry);
ssBuild.addScreenObject(animObj, animObj.worldLoc, &animObj.geometry);

// Hold off on adding the new one
ScreenSpaceObject shortObj = cluster.layoutObj;
//shortObj.setDrawOrder(?)
shortObj.setEnableTime(curTime+params.markerAnimationTime, 0.0);
ssBuild.addScreenObject(shortObj, shortObj.worldLoc, shortObj.geometry);
ssBuild.addScreenObject(shortObj, shortObj.worldLoc, &shortObj.geometry);

} else
ssBuild.addScreenObject(cluster.layoutObj, cluster.layoutObj.worldLoc, cluster.layoutObj.geometry);
ssBuild.addScreenObject(cluster.layoutObj, cluster.layoutObj.worldLoc, &cluster.layoutObj.geometry);
}

ssBuild.flushChanges(changes, drawIDs);
Expand Down
4 changes: 2 additions & 2 deletions common/WhirlyGlobeLib/src/MarkerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ SimpleIdentity MarkerManager::addMarkers(const std::vector<Marker *> &markers,co
// Handle the mask rendering if it's there
if (marker->maskID != EmptyIdentity && marker->maskRenderTargetID != EmptyIdentity) {
// Make a copy of the geometry, but target it to the mask render target
std::vector<ScreenSpaceConvexGeometry> geom = shape->getGeometry();
for (auto entry: geom) {
const std::vector<ScreenSpaceConvexGeometry> *geom = shape->getGeometry();
for (auto entry: *geom) {
entry.vertexAttrs.insert(SingleVertexAttribute(a_maskNameID, renderer->getSlotForNameID(a_maskNameID), (int)marker->maskID));
entry.renderTargetID = marker->maskRenderTargetID;
entry.progID = maskProgID;
Expand Down
25 changes: 11 additions & 14 deletions common/WhirlyGlobeLib/src/ScreenSpaceBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#import "ScreenSpaceBuilder.h"
#import "ScreenSpaceDrawableBuilder.h"
#import "WhirlyKitLog.h"

namespace WhirlyKit
{
Expand Down Expand Up @@ -342,7 +343,7 @@ void ScreenSpaceBuilder::addScreenObjects(std::vector<ScreenSpaceObject> &screen
{
ScreenSpaceObject &ssObj = screenObjects[ii];

addScreenObject(ssObj,ssObj.worldLoc,ssObj.geometry);
addScreenObject(ssObj,ssObj.worldLoc,&ssObj.geometry);
}
}

Expand All @@ -355,22 +356,23 @@ void ScreenSpaceBuilder::addScreenObjects(std::vector<ScreenSpaceObject *> &scre
{
ScreenSpaceObject *ssObj = screenObjects[ii];

addScreenObject(*ssObj, ssObj->worldLoc, ssObj->geometry);
addScreenObject(*ssObj, ssObj->worldLoc, &ssObj->geometry);
}
}

void ScreenSpaceBuilder::addScreenObject(const ScreenSpaceObject &ssObj,
const Point3d &worldLoc,
const std::vector<ScreenSpaceConvexGeometry> &geoms,
const std::vector<ScreenSpaceConvexGeometry> *geoms,
const std::vector<Eigen::Matrix3d> *places)
{
for (unsigned int ii=0;ii<geoms.size();ii++)
for (unsigned int ii=0;ii<geoms->size();ii++)
{
ScreenSpaceConvexGeometry geom = geoms[ii];
ScreenSpaceConvexGeometry geom = geoms->at(ii);
// Apply a matrix to the geometry for a given version of the placement
if (places) {
Eigen::Matrix3d placeMat = places->at(ii);
for (auto &pt: geom.coords) {
auto pt2d = (*places)[ii] * Point3d(pt.x(),pt.y(),1.0);
Point3d pt2d = placeMat * Point3d(pt.x(),pt.y(),1.0);
pt = Point2d(pt2d.x(),pt2d.y());
}
}
Expand Down Expand Up @@ -411,8 +413,9 @@ void ScreenSpaceBuilder::addScreenObject(const ScreenSpaceObject &ssObj,
{
Point3f dir3f(dir.x(),dir.y(),dir.z());
drawWrap->addVertex(coordAdapter,scale,startLoc, &dir3f, ssObj.rotation, Point2d(coord.x(),coord.y()), texCoord, &geom.color, &geom.vertexAttrs);
} else
} else {
drawWrap->addVertex(coordAdapter,scale,startLoc, NULL, ssObj.rotation, Point2d(coord.x(),coord.y()), texCoord, &geom.color, &geom.vertexAttrs);
}
}
for (unsigned int jj=0;jj<geom.coords.size()-2;jj++)
drawWrap->addTri(0+baseVert, jj+1+baseVert, jj+2+baseVert);
Expand Down Expand Up @@ -446,13 +449,7 @@ void ScreenSpaceBuilder::flushChanges(ChangeSet &changes,SimpleIDSet &drawIDs)
}
draws.clear();
}

ScreenSpaceConvexGeometry::ScreenSpaceConvexGeometry()
: progID(EmptyIdentity), color(255,255,255,255), drawPriority(-1), renderTargetID(EmptyIdentity)
, drawOrder(BaseInfo::DrawOrderTiles)
{
}


ScreenSpaceObject::ScreenSpaceObject()
: enable(true), startEnable(0.0), endEnable(0.0), worldLoc(0,0,0), endWorldLoc(0,0,0), startTime(0.0), endTime(0.0), offset(0,0), rotation(0), keepUpright(false), orderBy(-1)
{
Expand Down
22 changes: 21 additions & 1 deletion ios/apps/AutoTester/AutoTester/testCases/AirwayTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class AirwayTestCase: MaplyTestCase {
let buildAirways = false
let buildAirspaces = true
let buildLineLabels = true
let buildCenterLabels = false

func setupAirways(_ viewC: MaplyBaseViewController) {
DispatchQueue.global(qos: .default).async {
Expand Down Expand Up @@ -184,6 +185,7 @@ class AirwayTestCase: MaplyTestCase {
// Put the airspace vectors together
var airspaceVecs = [MaplyVectorObject]()
var labels = [MaplyScreenLabel]()
var centerLabels = [MaplyScreenLabel]()
for vec in vecObj.splitVectors() {
var include = false
if let highVal = vec.attributes?["US_HIGH"] as? Int {
Expand Down Expand Up @@ -211,6 +213,18 @@ class AirwayTestCase: MaplyTestCase {
labels.append(label)
airspaceVecs.append(vec)
}

if buildCenterLabels {
// Add a label right in the middle, for debugging
let centerLabel = MaplyScreenLabel()
centerLabel.loc = vec.centroid()
centerLabel.text = name
centerLabel.layoutImportance = 2.0
centerLabel.layoutPlacement = kMaplyLayoutCenter
if centerLabel.text != nil {
centerLabels.append(centerLabel)
}
}
}
}

Expand All @@ -226,7 +240,13 @@ class AirwayTestCase: MaplyTestCase {
kMaplyTextLayoutSpacing: 100.0, // 100 pixels between
// kMaplyTextLayoutSpacing: 0.0, // 100 pixels between
// kMaplyTextLayoutRepeat: 4, // As many as fit
kMaplyTextLayoutDebug: true
// kMaplyTextLayoutDebug: true
],
mode: .any)
}
if (!centerLabels.isEmpty) {
viewC.addScreenLabels(centerLabels, desc: [kMaplyFont: UIFont.boldSystemFont(ofSize: 48.0),
kMaplyTextColor: UIColor.red,
],
mode: .any)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1004,23 +1004,23 @@ - (void)setupLayoutObject:(LayoutObject &)retObj asBestOfLayoutObjects:(const st
if (topObject == nullptr || sorter(obj, topObject))
topObject = obj;

if (topObject == nullptr || topObject->obj.getGeometry().empty())
if (topObject == nullptr || topObject->obj.getGeometry()->empty())
return;

retObj.setWorldLoc(topObject->obj.getWorldLoc());
retObj.setDrawPriority(topObject->obj.getDrawPriority());
if (topObject->obj.hasRotation())
retObj.setRotation(topObject->obj.getRotation());

std::vector<ScreenSpaceConvexGeometry> allGeometry = topObject->obj.getGeometry();
const std::vector<ScreenSpaceConvexGeometry> *allGeometry = topObject->obj.getGeometry();

if (allGeometry.empty())
if (allGeometry->empty())
return;

retObj.layoutPts = allGeometry.back().coords;
retObj.selectPts = allGeometry.back().coords;
retObj.layoutPts = allGeometry->back().coords;
retObj.selectPts = allGeometry->back().coords;

for (auto geometry : allGeometry)
for (auto geometry : *allGeometry)
retObj.addGeometry(geometry);
}

Expand Down

0 comments on commit ffffff1

Please sign in to comment.