Skip to content

Commit ffffff1

Browse files
committed
Merge remote-tracking branch 'origin/topic/label-wrapup'
2 parents 5eb32a1 + 2bca613 commit ffffff1

7 files changed

Lines changed: 79 additions & 59 deletions

File tree

common/WhirlyGlobeLib/include/LinearTextBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class LinearWalker {
4242

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

4747
protected:
4848
VectorRing pts;

common/WhirlyGlobeLib/include/ScreenSpaceBuilder.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class ScreenSpaceBuilder
125125
/// Add a single screen space object
126126
void addScreenObject(const ScreenSpaceObject &screenObject,
127127
const Point3d &worldLoc,
128-
const std::vector<ScreenSpaceConvexGeometry> &geoms,
128+
const std::vector<ScreenSpaceConvexGeometry> *geoms,
129129
const std::vector<Eigen::Matrix3d> *places = nullptr);
130130

131131
/// Return the drawables constructed. Caller responsible for deletion.
@@ -178,20 +178,22 @@ class ScreenSpaceBuilder
178178
class ScreenSpaceConvexGeometry
179179
{
180180
public:
181-
ScreenSpaceConvexGeometry();
181+
EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
182+
183+
ScreenSpaceConvexGeometry() = default;
182184

183185
/// Texture ID used for just this object
184186
std::vector<SimpleIdentity> texIDs;
185187
/// Program ID used to render this geometry
186-
SimpleIdentity progID;
188+
SimpleIdentity progID = EmptyIdentity;
187189
/// Color for the geometry
188-
RGBAColor color;
190+
RGBAColor color = RGBAColor::white();
189191
/// Draw order
190-
int64_t drawOrder;
192+
int64_t drawOrder = BaseInfo::DrawOrderTiles;
191193
/// Draw priority
192-
int drawPriority;
194+
int drawPriority = -1;
193195
/// Render target
194-
SimpleIdentity renderTargetID;
196+
SimpleIdentity renderTargetID = EmptyIdentity;
195197
/// Vertex attributes applied to this piece of geometry
196198
SingleVertexAttributeSet vertexAttrs;
197199

@@ -247,7 +249,7 @@ class ScreenSpaceObject : public Identifiable
247249

248250
void addGeometry(const ScreenSpaceConvexGeometry &geom);
249251
void addGeometry(const std::vector<ScreenSpaceConvexGeometry> &geom);
250-
std::vector<ScreenSpaceConvexGeometry> getGeometry() const { return geometry; }
252+
const std::vector<ScreenSpaceConvexGeometry> *getGeometry() const { return &geometry; }
251253

252254
// Get a program ID either from the drawable state or geometry
253255
SimpleIdentity getTypicalProgramID();

common/WhirlyGlobeLib/src/LayoutManager.cpp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,10 @@ bool LayoutManager::runLayoutRules(PlatformThreadInfo *threadInfo,
628628
// wkLog("----");
629629

630630
for (auto layoutObj : container.objs) {
631+
layoutObj->newEnable = false;
632+
layoutObj->obj.layoutModelPlaces.clear();
633+
layoutObj->obj.layoutPlaces.clear();
634+
631635
// Layout along a shape
632636
if (!layoutObj->obj.layoutShape.empty()) {
633637
// Sometimes there are just a few instances
@@ -646,7 +650,7 @@ bool LayoutManager::runLayoutRules(PlatformThreadInfo *threadInfo,
646650
std::vector<Point3d> layoutModelInstances;
647651

648652
auto runs = textBuilder.getScreenVecs();
649-
// unsigned int ri=0;
653+
unsigned int ri=0;
650654
for (auto run: runs) {
651655
// wkLog("Run %d",ri++);
652656

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

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

712717
// Translate the glyph into that position
713718
Affine2d transPlace(Translation2d((centerPt.x()-worldScreenPt.x())/2.0,
714-
-(centerPt.y()-worldScreenPt.y())/2.0));
719+
(worldScreenPt.y()-centerPt.y())/2.0));
715720
double ang = -1.0 * (atan2(norm.y(),norm.x()) - M_PI/2.0);
716721
Matrix2d screenRot = Eigen::Rotation2Dd(ang).matrix();
717722
Matrix3d screenRotMat = Matrix3d::Identity();
718723
for (unsigned ix=0;ix<2;ix++)
719724
for (unsigned iy=0;iy<2;iy++)
720725
screenRotMat(ix, iy) = screenRot(ix, iy);
726+
Matrix3d overlapMat = transPlace.matrix() * screenRotMat * transOrigin.matrix();
721727
Matrix3d scaleMat = Eigen::AlignedScaling3d(resScale,resScale,1.0);
722-
Matrix3d overlapMat = transPlace.matrix() * screenRotMat * scaleMat * transOrigin.matrix();
723-
// Matrix3d overlapMat = transPlace.matrix() * transOrigin.matrix();
724-
layoutMats.push_back(transPlace.matrix() * screenRotMat * transOrigin.matrix());
725-
// layoutMats.push_back(transPlace.matrix() * transOrigin.matrix());
728+
Matrix3d testMat = screenRotMat * scaleMat * transOrigin.matrix();
729+
layoutMats.push_back(overlapMat);
726730

727731
// Check for overlap
728732
Point2dVector objPts; objPts.reserve(4);
729733
for (unsigned int oi=0;oi<4;oi++) {
730-
Point3d pt = overlapMat * Point3d(geom.coords[oi].x(),geom.coords[oi].y(),1.0);
731-
Point2d objPt(pt.x()+worldScreenPt.x(),pt.y()+worldScreenPt.y());
734+
Point3d pt = testMat * Point3d(geom.coords[oi].x(),geom.coords[oi].y(),1.0);
735+
Point2d objPt(pt.x()+centerPt.x(),pt.y()+centerPt.y());
732736
objPts.push_back(objPt);
733737
}
734738

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

742746
if (!overlapMan.checkObject(objPts)) {
743-
// wkLog(" Failed");
744747
failed = true;
745748
break;
746749
}
@@ -749,7 +752,7 @@ bool LayoutManager::runLayoutRules(PlatformThreadInfo *threadInfo,
749752
}
750753

751754
if (!failed) {
752-
layoutObj->obj.setRotation(textBuilder.getViewStateRotation());
755+
// layoutObj->obj.setRotation(textBuilder.getViewStateRotation());
753756
layoutModelInstances.push_back(worldPt);
754757
layoutInstances.push_back(layoutMats);
755758
numInstances++;
@@ -778,9 +781,6 @@ bool LayoutManager::runLayoutRules(PlatformThreadInfo *threadInfo,
778781
layoutObj->offset = Point2d(0.0,0.0);
779782
} else {
780783
isActive = false;
781-
layoutObj->newEnable = false;
782-
layoutObj->obj.layoutPlaces.clear();
783-
layoutObj->obj.layoutModelPlaces.clear();
784784
}
785785

786786
if (layoutObj->currentEnable != isActive) {
@@ -891,10 +891,10 @@ bool LayoutManager::runLayoutRules(PlatformThreadInfo *threadInfo,
891891
}
892892
}
893893

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

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

10431043
// And hold off on adding it
10441044
// todo: slicing, is this ok?
10451045
ScreenSpaceObject shortObj = layoutObj->obj;
10461046
//shortObj.setDrawOrder(?)
10471047
shortObj.setEnableTime(curTime+params.markerAnimationTime, 0.0);
1048-
ssBuild.addScreenObject(shortObj,shortObj.worldLoc,shortObj.geometry);
1048+
ssBuild.addScreenObject(shortObj,shortObj.worldLoc,&shortObj.geometry);
10491049
} else {
10501050
// It's boring, just add it
10511051
if (layoutObj->newEnable) {
10521052
// It's a single point placement
10531053
if (layoutObj->obj.layoutShape.empty())
1054-
ssBuild.addScreenObject(layoutObj->obj,layoutObj->obj.worldLoc,layoutObj->obj.geometry);
1054+
ssBuild.addScreenObject(layoutObj->obj,layoutObj->obj.worldLoc,&layoutObj->obj.geometry);
10551055
else {
10561056
// One or more placements along a path
1057-
for (unsigned int ii=0;ii<layoutObj->obj.layoutPlaces.size();ii++)
1058-
ssBuild.addScreenObject(layoutObj->obj, layoutObj->obj.layoutModelPlaces[ii], layoutObj->obj.geometry, &layoutObj->obj.layoutPlaces[ii]);
1057+
for (unsigned int ii=0;ii<layoutObj->obj.layoutPlaces.size();ii++) {
1058+
ssBuild.addScreenObject(layoutObj->obj, layoutObj->obj.layoutModelPlaces[ii], &layoutObj->obj.geometry, &layoutObj->obj.layoutPlaces[ii]);
1059+
}
10591060
}
10601061
}
10611062
}
@@ -1092,16 +1093,16 @@ void LayoutManager::updateLayout(PlatformThreadInfo *threadInfo,const ViewStateR
10921093
//animObj.setDrawOrder(?)
10931094
for (auto &geom : animObj.geometry)
10941095
geom.progID = params.motionShaderID;
1095-
ssBuild.addScreenObject(animObj, animObj.worldLoc, animObj.geometry);
1096+
ssBuild.addScreenObject(animObj, animObj.worldLoc, &animObj.geometry);
10961097

10971098
// Hold off on adding the new one
10981099
ScreenSpaceObject shortObj = cluster.layoutObj;
10991100
//shortObj.setDrawOrder(?)
11001101
shortObj.setEnableTime(curTime+params.markerAnimationTime, 0.0);
1101-
ssBuild.addScreenObject(shortObj, shortObj.worldLoc, shortObj.geometry);
1102+
ssBuild.addScreenObject(shortObj, shortObj.worldLoc, &shortObj.geometry);
11021103

11031104
} else
1104-
ssBuild.addScreenObject(cluster.layoutObj, cluster.layoutObj.worldLoc, cluster.layoutObj.geometry);
1105+
ssBuild.addScreenObject(cluster.layoutObj, cluster.layoutObj.worldLoc, &cluster.layoutObj.geometry);
11051106
}
11061107

11071108
ssBuild.flushChanges(changes, drawIDs);

common/WhirlyGlobeLib/src/MarkerManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ SimpleIdentity MarkerManager::addMarkers(const std::vector<Marker *> &markers,co
252252
// Handle the mask rendering if it's there
253253
if (marker->maskID != EmptyIdentity && marker->maskRenderTargetID != EmptyIdentity) {
254254
// Make a copy of the geometry, but target it to the mask render target
255-
std::vector<ScreenSpaceConvexGeometry> geom = shape->getGeometry();
256-
for (auto entry: geom) {
255+
const std::vector<ScreenSpaceConvexGeometry> *geom = shape->getGeometry();
256+
for (auto entry: *geom) {
257257
entry.vertexAttrs.insert(SingleVertexAttribute(a_maskNameID, renderer->getSlotForNameID(a_maskNameID), (int)marker->maskID));
258258
entry.renderTargetID = marker->maskRenderTargetID;
259259
entry.progID = maskProgID;

common/WhirlyGlobeLib/src/ScreenSpaceBuilder.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#import "ScreenSpaceBuilder.h"
2222
#import "ScreenSpaceDrawableBuilder.h"
23+
#import "WhirlyKitLog.h"
2324

2425
namespace WhirlyKit
2526
{
@@ -342,7 +343,7 @@ void ScreenSpaceBuilder::addScreenObjects(std::vector<ScreenSpaceObject> &screen
342343
{
343344
ScreenSpaceObject &ssObj = screenObjects[ii];
344345

345-
addScreenObject(ssObj,ssObj.worldLoc,ssObj.geometry);
346+
addScreenObject(ssObj,ssObj.worldLoc,&ssObj.geometry);
346347
}
347348
}
348349

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

358-
addScreenObject(*ssObj, ssObj->worldLoc, ssObj->geometry);
359+
addScreenObject(*ssObj, ssObj->worldLoc, &ssObj->geometry);
359360
}
360361
}
361362

362363
void ScreenSpaceBuilder::addScreenObject(const ScreenSpaceObject &ssObj,
363364
const Point3d &worldLoc,
364-
const std::vector<ScreenSpaceConvexGeometry> &geoms,
365+
const std::vector<ScreenSpaceConvexGeometry> *geoms,
365366
const std::vector<Eigen::Matrix3d> *places)
366367
{
367-
for (unsigned int ii=0;ii<geoms.size();ii++)
368+
for (unsigned int ii=0;ii<geoms->size();ii++)
368369
{
369-
ScreenSpaceConvexGeometry geom = geoms[ii];
370+
ScreenSpaceConvexGeometry geom = geoms->at(ii);
370371
// Apply a matrix to the geometry for a given version of the placement
371372
if (places) {
373+
Eigen::Matrix3d placeMat = places->at(ii);
372374
for (auto &pt: geom.coords) {
373-
auto pt2d = (*places)[ii] * Point3d(pt.x(),pt.y(),1.0);
375+
Point3d pt2d = placeMat * Point3d(pt.x(),pt.y(),1.0);
374376
pt = Point2d(pt2d.x(),pt2d.y());
375377
}
376378
}
@@ -411,8 +413,9 @@ void ScreenSpaceBuilder::addScreenObject(const ScreenSpaceObject &ssObj,
411413
{
412414
Point3f dir3f(dir.x(),dir.y(),dir.z());
413415
drawWrap->addVertex(coordAdapter,scale,startLoc, &dir3f, ssObj.rotation, Point2d(coord.x(),coord.y()), texCoord, &geom.color, &geom.vertexAttrs);
414-
} else
416+
} else {
415417
drawWrap->addVertex(coordAdapter,scale,startLoc, NULL, ssObj.rotation, Point2d(coord.x(),coord.y()), texCoord, &geom.color, &geom.vertexAttrs);
418+
}
416419
}
417420
for (unsigned int jj=0;jj<geom.coords.size()-2;jj++)
418421
drawWrap->addTri(0+baseVert, jj+1+baseVert, jj+2+baseVert);
@@ -446,13 +449,7 @@ void ScreenSpaceBuilder::flushChanges(ChangeSet &changes,SimpleIDSet &drawIDs)
446449
}
447450
draws.clear();
448451
}
449-
450-
ScreenSpaceConvexGeometry::ScreenSpaceConvexGeometry()
451-
: progID(EmptyIdentity), color(255,255,255,255), drawPriority(-1), renderTargetID(EmptyIdentity)
452-
, drawOrder(BaseInfo::DrawOrderTiles)
453-
{
454-
}
455-
452+
456453
ScreenSpaceObject::ScreenSpaceObject()
457454
: 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)
458455
{

ios/apps/AutoTester/AutoTester/testCases/AirwayTestCase.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class AirwayTestCase: MaplyTestCase {
5353
let buildAirways = false
5454
let buildAirspaces = true
5555
let buildLineLabels = true
56+
let buildCenterLabels = false
5657

5758
func setupAirways(_ viewC: MaplyBaseViewController) {
5859
DispatchQueue.global(qos: .default).async {
@@ -184,6 +185,7 @@ class AirwayTestCase: MaplyTestCase {
184185
// Put the airspace vectors together
185186
var airspaceVecs = [MaplyVectorObject]()
186187
var labels = [MaplyScreenLabel]()
188+
var centerLabels = [MaplyScreenLabel]()
187189
for vec in vecObj.splitVectors() {
188190
var include = false
189191
if let highVal = vec.attributes?["US_HIGH"] as? Int {
@@ -211,6 +213,18 @@ class AirwayTestCase: MaplyTestCase {
211213
labels.append(label)
212214
airspaceVecs.append(vec)
213215
}
216+
217+
if buildCenterLabels {
218+
// Add a label right in the middle, for debugging
219+
let centerLabel = MaplyScreenLabel()
220+
centerLabel.loc = vec.centroid()
221+
centerLabel.text = name
222+
centerLabel.layoutImportance = 2.0
223+
centerLabel.layoutPlacement = kMaplyLayoutCenter
224+
if centerLabel.text != nil {
225+
centerLabels.append(centerLabel)
226+
}
227+
}
214228
}
215229
}
216230

@@ -226,7 +240,13 @@ class AirwayTestCase: MaplyTestCase {
226240
kMaplyTextLayoutSpacing: 100.0, // 100 pixels between
227241
// kMaplyTextLayoutSpacing: 0.0, // 100 pixels between
228242
// kMaplyTextLayoutRepeat: 4, // As many as fit
229-
kMaplyTextLayoutDebug: true
243+
// kMaplyTextLayoutDebug: true
244+
],
245+
mode: .any)
246+
}
247+
if (!centerLabels.isEmpty) {
248+
viewC.addScreenLabels(centerLabels, desc: [kMaplyFont: UIFont.boldSystemFont(ofSize: 48.0),
249+
kMaplyTextColor: UIColor.red,
230250
],
231251
mode: .any)
232252
}

ios/library/WhirlyGlobe-MaplyComponent/src/control/MaplyBaseInteractionLayer.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,23 +1004,23 @@ - (void)setupLayoutObject:(LayoutObject &)retObj asBestOfLayoutObjects:(const st
10041004
if (topObject == nullptr || sorter(obj, topObject))
10051005
topObject = obj;
10061006

1007-
if (topObject == nullptr || topObject->obj.getGeometry().empty())
1007+
if (topObject == nullptr || topObject->obj.getGeometry()->empty())
10081008
return;
10091009

10101010
retObj.setWorldLoc(topObject->obj.getWorldLoc());
10111011
retObj.setDrawPriority(topObject->obj.getDrawPriority());
10121012
if (topObject->obj.hasRotation())
10131013
retObj.setRotation(topObject->obj.getRotation());
10141014

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

1017-
if (allGeometry.empty())
1017+
if (allGeometry->empty())
10181018
return;
10191019

1020-
retObj.layoutPts = allGeometry.back().coords;
1021-
retObj.selectPts = allGeometry.back().coords;
1020+
retObj.layoutPts = allGeometry->back().coords;
1021+
retObj.selectPts = allGeometry->back().coords;
10221022

1023-
for (auto geometry : allGeometry)
1023+
for (auto geometry : *allGeometry)
10241024
retObj.addGeometry(geometry);
10251025
}
10261026

0 commit comments

Comments
 (0)