OBJ Wavefront file: issues due to face vertex order - wavefront

I am facing some strange problem with a simple obj-file I created. The obj-file contains 8 vertices which represent the corners of a cuboid-like shape. For each of the vertices I calculate a vertex normal (which I need for rendering). The object contains 12 triangle faces which are defined by the references to the vertices and normals. The order of the vertices to define a face seems to make a difference to the normal orientation of faces. E.g. the faces
"f 2//2 1//1 3//3" and "f 1//1 2//2 3//3" might not have the same normal orientation.
Can anyone tell me, how the vertices to define a triangular face should be ordered? I have not found information about this (only that vertices are ordered counter-clockwise by default, though Im not sure what "counter-clockwise" actually means in a 3D point cloud).
I'm attaching a screenshot (used CloudCompare), which shows the obj with incorrect (top) and correct (bottom) face orientations.
.
The .obj file code I've added below. Note: the second obj only differs in the face vertex order.
Any help is very much appreciated. Thank you!
Incorrect face orientation:
v 142.275 -164.684 -222.937
v 144.341 -156.611 -189.123
v 144.475 -189.798 -192.755
v 142.505 -195.249 -224.626
v 330.045 -162.613 -234.9
v 332.11 -154.539 -201.085
v 332.245 -187.727 -204.718
v 330.274 -193.177 -236.589
vn -0.988559636 0.113057396 -0.09983923
vn -0.949405612 0.193458398 0.247392061
vn -0.965486533 -0.148224101 0.214162018
vn -0.972490893 -0.202126966 -0.11578494
vn 0.965175897 0.134606199 -0.224313751
vn 0.96863934 0.214622417 0.125200028
vn 0.98787863 -0.126679515 0.089711275
vn 0.954142849 -0.180867505 -0.238533788
f 1//1 2//2 3//3
f 1//1 3//3 4//4
f 5//5 6//5 7//7
f 5//5 7//7 8//8
f 1//1 2//2 6//6
f 1//1 5//5 6//6
f 1//1 4//4 8//8
f 1//1 5//5 8//8
f 3//3 6//6 7//7
f 2//2 3//3 6//6
f 3//3 8//8 7//7
f 3//3 4//4 8//8
Correct face orientation
v 142.275 -164.684 -222.937
v 144.341 -156.611 -189.123
v 144.475 -189.798 -192.755
v 142.505 -195.249 -224.626
v 330.045 -162.613 -234.9
v 332.11 -154.539 -201.085
v 332.245 -187.727 -204.718
v 330.274 -193.177 -236.589
vn -0.988559636 0.113057396 -0.09983923
vn -0.949405612 0.193458398 0.247392061
vn -0.965486533 -0.148224101 0.214162018
vn -0.972490893 -0.202126966 -0.11578494
vn 0.965175897 0.134606199 -0.224313751
vn 0.96863934 0.214622417 0.125200028
vn 0.98787863 -0.126679515 0.089711275
vn 0.954142849 -0.180867505 -0.238533788
f 2//2 1//1 3//3
f 3//3 1//1 4//4
f 5//5 6//6 7//7
f 5//5 7//7 8//8
f 1//1 2//2 6//6
f 5//5 1//1 6//6
f 4//4 1//1 8//8
f 1//1 5//5 8//8
f 6//6 3//3 7//7
f 2//2 3//3 6//6
f 3//3 8//8 7//7
f 3//3 4//4 8//8

Related

SQL Error [1248] [42000]: Every derived table must have its own alias

Issues : SQL Error [1248] [42000]: Every derived table must have its own alias
Tried : remove all the alias and use full path instead of alias
Original Script:
SELECT *
FROM
(SELECT 'OfferItm9' AS OfferNo,
O.DocNo,
O.Stkno,
O.OfferPrice,
O.StartDateItm,
O.EndDateItm
FROM OfferItm9 O
WHERE O.EndDateItm>=CURDATE()
AND O.Active = '1'
AND O.UOM = 'U'
UNION SELECT 'OfferItm8' AS OfferNo,
O.DocNo,
O.Stkno,
O.OfferPrice,
O.StartDateItm,
O.EndDateItm
FROM OfferItm8 O
WHERE O.EndDateItm>=CURDATE()
AND O.Active = '1'
AND O.UOM = 'U'
)
The subquery in your query above needs an alias, that is all:
SELECT *
FROM
(
SELECT 'OfferItm9' AS OfferNo, O.DocNo, O.Stkno, O.OfferPrice, O.StartDateItm, O.EndDateItm
FROM OfferItm9 O
WHERE O.EndDateItm >= CURDATE() AND O.Active = '1' AND O.UOM = 'U'
UNION ALL
SELECT 'OfferItm8', O.DocNo, O.Stkno, O.OfferPrice, O.StartDateItm, O.EndDateItm
FROM OfferItm8 O
WHERE O.EndDateItm >= CURDATE() AND O.Active = '1' AND O.UOM = 'U'
) t;
But, I don't even see the point of the subquery, so just use:
SELECT 'OfferItm9' AS OfferNo, O.DocNo, O.Stkno, O.OfferPrice, O.StartDateItm, O.EndDateItm
FROM OfferItm9 O
WHERE O.EndDateItm >= CURDATE() AND O.Active = '1' AND O.UOM = 'U'
UNION ALL
SELECT 'OfferItm8', O.DocNo, O.Stkno, O.OfferPrice, O.StartDateItm, O.EndDateItm
FROM OfferItm8 O
WHERE O.EndDateItm >= CURDATE() AND O.Active = '1' AND O.UOM = 'U';
Note: Use UNION ALL here for performance.
You need to name the sub-query result with an alias.
SELECT * FROM
( SELECT A, B, C, FROM TABLE
) TABLE_ALIAS
Where TABLE_ALIAS is the alias for the derived table.

sum of subquery select

How can sum subqueries like total_3m and total_30?
SUM(p.quantity),
SUM(ptpq.procurement_quantity),
SUM(p.quantity*ptpq.procurement_quantity) as ostatok,
(SELECT SUM(op.quantity*ptpq.procurement_quantity) FROM oc_order_product op LEFT JOIN oc_order o ON (op.order_id = o.order_id) LEFT JOIN oc_procurement_to_product_quantity ptpq ON (ptpq.product_id = op.product_id) WHERE (o.order_status_id is null or (o.order_status_id != 0 AND o.order_status_id != 19 AND o.order_status_id != 8)) and op.product_id = pptp.product_id AND DATE(o.date_added) >= '2020-03-17' AND DATE(o.date_added) <= '2020-06-17') as total_3m,
(SELECT SUM(op.quantity*ptpq.procurement_quantity) FROM oc_order_product op LEFT JOIN oc_order o ON (op.order_id = o.order_id) LEFT JOIN oc_procurement_to_product_quantity ptpq ON (ptpq.product_id = op.product_id) WHERE (o.order_status_id is null or (o.order_status_id != 0 AND o.order_status_id != 19 AND o.order_status_id != 8)) and op.product_id = pptp.product_id AND DATE(o.date_added) >= '2020-05-18' AND DATE(o.date_added) <= '2020-06-17') as total_30
FROM oc_procurement_product pp
LEFT JOIN oc_procurement_product_to_product pptp ON (pp.procurement_product_id = pptp.procurement_product_id)
LEFT JOIN oc_procurement_to_product_quantity ptpq ON (ptpq.product_id = pptp.product_id)
LEFT JOIN oc_product p ON (p.product_id = pptp.product_id)
GROUP BY pp.procurement_product_id
I tried like this
(SELECT SUM(col_sum)
FROM ((SELECT SUM(op.quantity*ptpq.procurement_quantity) as col_sum
FROM oc_order_product op
LEFT JOIN oc_order o
ON (op.order_id = o.order_id)
LEFT JOIN oc_procurement_to_product_quantity ptpq
ON (ptpq.product_id = op.product_id)
WHERE (o.order_status_id is null
or (o.order_status_id != 0
AND o.order_status_id != 19
AND o.order_status_id != 8))
and op.product_id = pptp.product_id
AND DATE(o.date_added) >= '2020-03-17'
AND DATE(o.date_added) <= '2020-06-17') as total_3m))
but catch error that unknown column pptp.product_id in 'where clause'
I solved it by something like in this two answers
MySQL: Sum of multiple subqueries
MySQL: sum values from subqueries
by select from my select
SELECT
t.procurement_product_id,
SUM(t.total_3m),
SUM(t.total_30),
SUM(t.ostatok) as ostatok,
t.stock,
(SUM(t.ostatok) + t.stock) as sum_stock
FROM (
SELECT pp.procurement_product_id,
p.quantity,
ptpq.procurement_quantity,
(p.quantity*ptpq.procurement_quantity) as ostatok,
(SELECT SUM(quantity)
FROM oc_procurement_stock WHERE procurement_product_id = pp.procurement_product_id) as stock,
(SELECT SUM(op.quantity*ptpq.procurement_quantity) as col_sum FROM oc_order_product op
LEFT JOIN oc_order o ON (op.order_id = o.order_id)
LEFT JOIN oc_procurement_to_product_quantity ptpq ON (ptpq.product_id = op.product_id)
WHERE (o.order_status_id is null
OR (o.order_status_id != 0 AND o.order_status_id != 19 AND o.order_status_id != 8)) AND op.product_id = pptp.product_id
AND DATE(o.date_added) >= '2020-03-17'
AND DATE(o.date_added) <= '2020-06-17') as total_3m,
(SELECT SUM(op.quantity*ptpq.procurement_quantity)
FROM `oc_order_product` op
LEFT JOIN `oc_order` o ON (op.order_id = o.order_id)
LEFT JOIN `oc_procurement_to_product_quantity` ptpq ON (ptpq.product_id = op.product_id)
WHERE (o.order_status_id is null or (o.order_status_id != 0 AND o.order_status_id != 19 AND o.order_status_id != 8))
AND op.product_id = pptp.product_id
AND DATE(o.date_added) >= '2020-05-18'
AND DATE(o.date_added) <= '2020-06-17') as total_30
FROM oc_procurement_product pp
LEFT JOIN oc_procurement_product_to_product pptp ON (pp.procurement_product_id = pptp.procurement_product_id)
LEFT JOIN `oc_procurement_to_product_quantity` ptpq ON (ptpq.product_id = pptp.product_id)
LEFT JOIN `oc_product` p ON (p.product_id = pptp.product_id)) t GROUP BY t.procurement_product_id```

jess multislot value matching ignoring the order

I am trying to check if there already exists the same instance or not.
(defemplate justificand (slot consq) (multislot antes))
(assert (justificand (consq s) (antes p q r))) ;;; order p q r
(defrule test
(exists (justificand (consq s) (antes q p r))) ;;; order q p r
=>
(printout t "matching success " crlf))
In my case, I assert a justificand with (antes p q r) but the order of p, q and r
is not important. So, test rule need to succeed even if it test with (antes q p r).
But, jess seems to consider order of multislot values for matching.
Any method to ignore the order of multislot values for matching?
Thanks
With your deftemplate and this function
(deffunction unleq (?l1 $?l2)
(and (eq (length$ ?l1)(length$ $?l2))
(eq (length$ ?l1)(length$ (intersection$ ?l1 $?l2)))))
and inserting facts:
(deffacts f1
(justificand (consq s1) (antes p q r))
(justificand (consq s2) (antes r p q))
(justificand (consq s3) (antes p q x))
(justificand (consq s4) (antes p q))
(justificand (consq s4) (antes r q q p p)))
this rule fires:
(defrule match
(justificand (consq ?s) (antes $?pqr&:(unleq $?pqr p q r)))
=>
(printout t "match for " ?s crlf))
giving
match for s2
match for s1

How can I do matching on a field containing text that alternates with spaces?

I have an Elasticsearch v2.4.1 index in which I store values from a JSON feed. Sometimes I get values separated by spaces in some fields, like:
"titulo" : "E l a ñ o q u e e l m e r c a d o d e j ó d e a s u s t a r"
This happens around 15% of the time and prevents queries such as:
localhost:9200/indice/_search?q=titulo:mercado
To match the document above.
I think the problem could be solved by using some sort of CharFilter, I thought of the N-gram filter but that does the opposite. I know this might be complex since ES should, at some level, infer the language (or maybe I could specify it); deal with ambiguities and so on...
Another examples of the same:
"title" : "El g a l a r d ó n se e n t r e g a r á el p r ó x i m o día 2 4"
"title" : "G a m a a c t u a l i z a d a d e b o m b a s d e calor A q u a t e r m i c"
"title" : "K a s p e r s k y : m á s q u e a n t i v i r u s"

Cannot see mySQL COUNT from 3rd table

I have posted another message like this. But none helped. So I have done some more reading and I have this code which works to a point:
EDIT NEW VERSION & NEW ISSUE
SELECT i.*, o.organ_name, o.organ_logo, vtable.*
FROM heroku_056eb661631f253.op_ideas i
JOIN
(SELECT
COUNT(v.agree) as agree,
COUNT(v.disagree = 1 or null) as disagree,
COUNT(v.obstain = 1 or null) as abstain
FROM op_idea_vote v
) AS vtable
LEFT JOIN op_organs o ON i.post_type = o.organs_id
There is only 1 row in the op_idea_vote table, and 3 in the op_ideas table. But it's giving each row the total in each op_ideas row
EDIT WORKING SOLUTION
Thanks to WayneC, here is the working code:
SELECT i.*, o.organ_name, o.organ_logo, vtable.*
FROM heroku_056eb661631f253.op_ideas i
JOIN
(SELECT v.idea_Id,
COUNT(v.agree = 1 or null) as agree,
COUNT(v.disagree = 1 or null) as disagree,
COUNT(v.obstain = 1 or null) as abstain
FROM op_idea_vote v
GROUP BY v.idea_id
) AS vtable ON vtable.idea_id = i.idea_id
LEFT JOIN op_organs o ON i.post_type = o.organs_id
WHERE idea_geo = 'International';
Try this
SELECT i.*, o.organ_name, o.organ_logo, vtable.*
FROM heroku_056eb661631f253.op_ideas i
JOIN
(SELECT
COUNT(v.agree) as agree,
COUNT(v.disagree = 1 or null) as disagree,
COUNT(v.obstain = 1 or null) as abstain
FROM op_idea_vote v
GROUP BY v.idea_id
) AS vtable ON vtable.idea_id = i.idea_id
LEFT JOIN op_organs o ON i.post_type = o.organs_id
The answer below was missing the group by, and join condition for vtable
Here's your original query
SELECT i.*, o.organ_name, o.organ_logo
FROM heroku_056eb661631f253.op_ideas i
JOIN
(SELECT
COUNT(v.agree) as agree,
COUNT(v.disagree = 1 or null) as disagree,
COUNT(v.obstain = 1 or null) as abstain
FROM op_idea_vote v, op_ideas i
WHERE v.idea_id = i.idea_id
) AS vtable
LEFT JOIN op_organs o ON i.post_type = o.organs_id
vtable is a subquery masquerading as a table you're joining to - in terms of getting the fields to be returned with the query results, it's no different from joining a normal table. You have to select the fields you want returned in the main query, or they won't be returned.
SELECT i.*, o.organ_name, o.organ_logo, vtable.*
FROM heroku_056eb661631f253.op_ideas i
JOIN
(SELECT
COUNT(v.agree) as agree,
COUNT(v.disagree = 1 or null) as disagree,
COUNT(v.obstain = 1 or null) as abstain
FROM op_idea_vote v, op_ideas i
WHERE v.idea_id = i.idea_id
) AS vtable
LEFT JOIN op_organs o ON i.post_type = o.organs_id